Hello,

I am trying to troubleshoot this problem using codeigniter.

I am following a tutorial and getting this error after installing the ready-to-use-uncomplete-ci-script. Therefore, I still have to edit things out to make it work, which not all of them is being taught in the tutorial.

----------------------------

// all of this printed out in web browser text 

load->model(array('Mediatutorialaccount')); $this->load->helper(array('html','url')); } function index(){ $data['title'] = 'Member only'; $sub_data = array( 'extra_script' => $this->Mediatutorialaccount->extra_script(), 'column_1' => $this->Mediatutorialaccount->update_status(), 'column_2' => $this->Mediatutorialaccount->profile_detail() ); $data['body'] = $this->load->view('_member_area', $sub_data, true); $this->load->view('_output_html', $data); } }
404 Page Not Found

The page you requested was not found.

----------------------------

routes.php

$route['default_controller'] = 'Member_area';
$route['404_override'] = '';

controllers/member_area.php

class Member_area extends CI_Controller {
    function __construct()
    {
        parent::__construct();
       $this->load->model(array('Mediatutorialaccount'));
        $this->load->helper(array('html','url'));
    }

    function index(){
        $data['title'] = 'Member only';
        $sub_data = array(
            'extra_script' => $this->Mediatutorialaccount->extra_script(),
            'column_1'  => $this->Mediatutorialaccount->update_status(),
            'column_2'  => $this->Mediatutorialaccount->profile_detail()
        );
        $data['body'] = $this->load->view('_member_area', $sub_data, true);
        $this->load->view('_output_html', $data);
    }

}

views/_member_area.php

<!--script BEGIN-->
<script type="text/javascript">
$(document).ready(function(){
  get_html_data(base_url+"profile/show_details/",'', 'profile_detail_loading', 'profile_detail');
});

function edit_detail(){
    get_html_data(base_url+"profile/show_details/edit/",'', 'profile_detail_loading', 'profile_detail');
}

function edit_detail_pass(){
    get_html_data(base_url+"profile/show_details/edit/pass/",'', 'profile_detail_loading', 'profile_detail');
}

function kembali(){
    get_html_data(base_url+"profile/show_details/",'', 'profile_detail_loading', 'profile_detail');
}

<?=$extra_script?>
</script>
<!--script END-->
<style>
#profile_detail table td{
  vertical-align: text-top;
}
</style>
<div class="column_1" style="width:400px;">
    <?=$column_1?>
</div>

<div class="column_2" style="width:285px;">
    <?=$column_2?>
</div>

views/_output_html.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
    <title><?=$title?></title>

    <link href="<?=base_url()?>templates/css/general.css" rel="stylesheet" type="text/css" />
    <script src="<?=base_url()?>templates/js/functions.js" type="text/javascript" language="javascript"></script>
    <script src="<?=base_url()?>templates/js/jquery-1.6.1.min.js" type="text/javascript" language="javascript"></script>
    <!-- script lanjutan-->
    <script type="text/javascript">
    var base_url = "<?=base_url()?>";
    </script>

</head>
<body>


<!--BEGIN MAIN DIV-->
<div class="mainDiv">
<?=$body?>
</div>
<!--END OF MAIN DIV-->

    </body>
</html>

Recommended Answers

All 19 Replies

If you want to load your model and your helpers on the index, they need to be included within the index functions. Else, you can load them in the autoload.php or in the class construct.

public function index()
{
    //You can also autoload these in the autoload.php file in the config directory.
    $this->load->model('Mediatutorialaccount');
    $this->load->helper('html');
    $this->load->helper('url');

    $data['title'] = 'Members Only';
    $sub_data = array( 
                    'extra_script' => $this->Mediatutorialaccount->extra_script(), 
                    'column_1' => $this->Mediatutorialaccount->update_status(), 
                    'column_2' => $this->Mediatutorialaccount->profile_detail() 
                    );

    $data['body'] = $this->load->view('_member_area', $sub_data, true);

    $this->load->view('_output_html', $data); 

}

This won't really help, but you should give Laravel a shot... it's much nicer and a lot more advance.

ok, I'll try reloading the those things in the autoload:

autoload.php

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
|   $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('html', 'url');


/*
| -------------------------------------------------------------------
|  Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files.  Otherwise, leave it blank.
|
*/

$autoload['config'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file.  For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/

$autoload['language'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['model'] = array('model1', 'model2');
|
*/

$autoload['model'] = array('Mediatutorialaccount');


/* End of file autoload.php */
/* Location: ./application/config/autoload.php */

controllers/member_area.php

<?
/***************************************************************************
* Mediatutorial.web.id
***************************************************************************/
class Member_area extends CI_Controller {
    function __construct()
    {
        parent::__construct();
       $this->load->model(array('Mediatutorialaccount'));
        $this->load->helper(array('html','url'));
    }

    function index(){

        //You can also autoload these in the autoload.php file in the config directory.
        //$this->load->model('Mediatutorialaccount');
        //$this->load->helper('html');
        //$this->load->helper('url');

        $data['title'] = 'Member only';
        $sub_data = array(
            'extra_script' => $this->Mediatutorialaccount->extra_script(),
            'column_1'  => $this->Mediatutorialaccount->update_status(),
            'column_2'  => $this->Mediatutorialaccount->profile_detail()
        );
        $data['body'] = $this->load->view('_member_area', $sub_data, true);
        $this->load->view('_output_html', $data);
    }

}

I still receiving the similar error message:

ok, I'll try reloading the those things in the autoload:

autoload.php

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
|   $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('html', 'url');


/*
| -------------------------------------------------------------------
|  Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files.  Otherwise, leave it blank.
|
*/

$autoload['config'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file.  For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/

$autoload['language'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
|   $autoload['model'] = array('model1', 'model2');
|
*/

$autoload['model'] = array('Mediatutorialaccount');


/* End of file autoload.php */
/* Location: ./application/config/autoload.php */

controllers/member_area.php

<?
/***************************************************************************
* Mediatutorial.web.id
***************************************************************************/
class Member_area extends CI_Controller {
    function __construct()
    {
        parent::__construct();
       $this->load->model(array('Mediatutorialaccount'));
        $this->load->helper(array('html','url'));
    }

    function index(){

        //You can also autoload these in the autoload.php file in the config directory.
        //$this->load->model('Mediatutorialaccount');
        //$this->load->helper('html');
        //$this->load->helper('url');

        $data['title'] = 'Member only';
        $sub_data = array(
            'extra_script' => $this->Mediatutorialaccount->extra_script(),
            'column_1'  => $this->Mediatutorialaccount->update_status(),
            'column_2'  => $this->Mediatutorialaccount->profile_detail()
        );
        $data['body'] = $this->load->view('_member_area', $sub_data, true);
        $this->load->view('_output_html', $data);
    }

}

I still receiving the similar error message:

load->model(array('Mediatutorialaccount')); $this->load->helper(array('html','url')); } function index(){ //You can also autoload these in the autoload.php file in the config directory. //$this->load->model('Mediatutorialaccount'); //$this->load->helper('html'); //$this->load->helper('url'); $data['title'] = 'Member only'; $sub_data = array( 'extra_script' => $this->Mediatutorialaccount->extra_script(), 'column_1' => $this->Mediatutorialaccount->update_status(), 'column_2' => $this->Mediatutorialaccount->profile_detail() ); $data['body'] = $this->load->view('_member_area', $sub_data, true); $this->load->view('_output_html', $data); } }
404 Page Not Found

The page you requested was not found.

----------------------

sorry, I am not interested to learn lavarel yet, since it's not yet popular my country's job market. (CI is the most popular / CakePHP second - I plan to learn CI first until I am fluent at it)

you dont need to load your helpers in the construct if you autoload them.. Also, you dont need to put the name of your model in a array

Example: $this->load->model('model_name');

Why are you doing this?

 $data['body'] = $this->load->view('_member_area', $sub_data, true);
$this->load->view('_output_html', $data);

Are you using a templating system? If so, which one?
Else, you can do this to load your view files.

$this->load->view('view_header_file', $data);
$this->load->view('view_body_file');
$this->load->view('view_footer_file');

All I'll say is: thank god that Davy is at last using a framework.

Nice one for taking the advice, and hope that your future in CI goes well. It's amazing to see the difference in the quality of your code, just by using CI. Well done!

@mattster: thanks for the compliment, I am learning CI in parallel to using native PHP at work. I still can't really apply CI at work before having at least some skill at it.

I just have to wait until at least I can create a simple CMS website with CI and know how to convert ready-to-use HTML templates to CI then I can start using it at work.

@gabrielcastillo: yes, I am using a ready to use CI templates - which is actually from a tutorial that I purchase.

I can show you the code if I need to. I basically just trying to make the given codes works! Evenif I have to modify it.

controllers/member_area.php

class Member_area extends CI_Controller {
   /* function __construct()
    {
        parent::__construct();
       $this->load->model(array('Mediatutorialaccount'));
        $this->load->helper(array('html','url'));
    } */

    function index(){

        //You can also autoload these in the autoload.php file in the config directory.
        //$this->load->model('Mediatutorialaccount');
        //$this->load->helper('html');
        //$this->load->helper('url');

        $data['title'] = 'Member only';
        $sub_data = array(
            'extra_script' => $this->Mediatutorialaccount->extra_script(),
            'column_1'  => $this->Mediatutorialaccount->update_status(),
            'column_2'  => $this->Mediatutorialaccount->profile_detail()
        );
        $data['body'] = $this->load->view('_member_area', $sub_data, true);
        $this->load->view('_output_html', $data);
    }

}

_output_html.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
    <title><?=$title?></title>

    <link href="<?=base_url()?>templates/css/general.css" rel="stylesheet" type="text/css" />
    <script src="<?=base_url()?>templates/js/functions.js" type="text/javascript" language="javascript"></script>
    <script src="<?=base_url()?>templates/js/jquery-1.6.1.min.js" type="text/javascript" language="javascript"></script>
    <!-- script lanjutan-->
    <script type="text/javascript">
    var base_url = "<?=base_url()?>";
    </script>

</head>
<body>


<!--BEGIN MAIN DIV-->
<div class="mainDiv">
<?=$body?>
</div>
<!--END OF MAIN DIV-->

    </body>
</html>

So in this code, there is only _member_area which is inserted in between of _output_html

What makes me wonder is why I still having this error:

// printed in web browser

load->model(array('Mediatutorialaccount')); $this->load->helper(array('html','url')); } function index(){ //You can also autoload these in the autoload.php file in the config directory. //$this->load->model('Mediatutorialaccount'); //$this->load->helper('html'); //$this->load->helper('url'); $data['title'] = 'Member only'; $sub_data = array( 'extra_script' => $this->Mediatutorialaccount->extra_script(), 'column_1' => $this->Mediatutorialaccount->update_status(), 'column_2' => $this->Mediatutorialaccount->profile_detail() ); $data['body'] = $this->load->view('_member_area', $sub_data, true); $this->load->view('_output_html', $data); } }
404 Page Not Found

The page you requested was not found.

Those are not really errors - they are PHP code that isn't getting parsed. Somewhere you have a line that starts with "load->model(array('Mediatutorialaccount'))" which is not inside of a <?php block.

I would recommend searching the whole directory for the word "Mediatutorialaccount" to try to find where this is.

You will get a 404 if the URL you're trying to get to doesn't, by default, match controllerName/methodName. What URL are you trying to load?

the subdata is a multidimensional array.

it must be expressed like this..

$data['sub_data'] = array(

        'extra_script' => $this->Mediatutorialaccount->extra_script(),
        'column_1'  => $this->Mediatutorialaccount->update_status(),
        'column_2'  => $this->Mediatutorialaccount->profile_detail()
    );

you can then iterate them using foreach or whatever is your preferences in iterating an array.

First of all, I don't think you can use $this->load->model() having an array as parameter. You can't do a $this->load->model(array('Mediatutorialaccount'));
Secondly, you have $data['sub_data'] which is an array, but you want to echo it. You must use print_r(), or iterate the array.

Okay, here is my revision:

controllers/member_area.php

<?php
/***************************************************************************
* Mediatutorial.web.id
***************************************************************************/
class Member_area extends CI_Controller {
   /* function __construct()
    {
        parent::__construct();
       $this->load->model(array('Mediatutorialaccount'));
        $this->load->helper(array('html','url'));
    } */

    function index(){

        //You can also autoload these in the autoload.php file in the config directory.
        //$this->load->model('Mediatutorialaccount');
        //$this->load->helper('html');
        //$this->load->helper('url');

        $data['title'] = 'Member only';
        $data['sub_data'] = array(
            'extra_script' => $this->Mediatutorialaccount->extra_script(),
            'column_1'  => $this->Mediatutorialaccount->update_status(),
            'column_2'  => $this->Mediatutorialaccount->profile_detail()
        );
        $data['body'] = $this->load->view('_member_area', $data['sub_data'], true);
        $this->load->view('_output_html', $data);
    }

}

?>

views/_member_area.php

<!--script BEGIN-->
<script type="text/javascript">
$(document).ready(function(){
  get_html_data(base_url+"profile/show_details/",'', 'profile_detail_loading', 'profile_detail');
});

function edit_detail(){
    get_html_data(base_url+"profile/show_details/edit/",'', 'profile_detail_loading', 'profile_detail');
}

function edit_detail_pass(){
    get_html_data(base_url+"profile/show_details/edit/pass/",'', 'profile_detail_loading', 'profile_detail');
}

function kembali(){
    get_html_data(base_url+"profile/show_details/",'', 'profile_detail_loading', 'profile_detail');
}

<?=$extra_script?>
</script>
<!--script END-->
<style>
#profile_detail table td{
  vertical-align: text-top;
}
</style>
<div class="column_1" style="width:400px;">
    <?php print_r($column_1);?>
</div>

<div class="column_2" style="width:285px;">
    <?php=$column_2?>
</div>

views/_output_html.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
    <title><?php=$title?></title>

    <link href="<?php=base_url();?>templates/css/general.css" rel="stylesheet" type="text/css" />
    <script src="<?php=base_url();?>templates/js/functions.js" type="text/javascript" language="javascript"></script>
    <script src="<?php=base_url();?>templates/js/jquery-1.6.1.min.js" type="text/javascript" language="javascript"></script>
    <!-- script lanjutan-->
    <script type="text/javascript">
    var base_url = "<?php=base_url();?>";
    </script>

</head>
<body>


<!--BEGIN MAIN DIV-->
<div class="mainDiv">
<?php=$body?>
</div>
<!--END OF MAIN DIV-->

    </body>
</html>

Now, all I have is a blank white page whenever I try to load:

this url: http://localhost/CI-202-profile/member_area

@Adrian_5: I still do not understand what you mean - I try to use: views/_member_area.php

<?php print_r($column_1);?>

And still do not see anything printed. All I have is a blank white page.

this is not right in member_area ... <?php=$column_2?>. This is not right either in _output_html <?php=$body?>

in your view you need to either use <?php echo base_url(); ?> or <?= base_url(); ?>

if you use <?= base_url(); ?> your server needs to have read short_tags enabled.

as already been suggested, stay away from using those short tags.

I hate adding more confusion to a broken source codes, so I have decided to write a pretty simple quidelines on the basics of CI. You can either do it like this or follow the tutorials available online.

Before anything else, decide which helpers and libraries will be needed by the controller. If the helpers and libraries are needed throughout the application, then include them in the application/config/autoload.php, else include them in the constructor or inside the method if the requirement of such helpers and libraries is isolated ONLY to such method.

1. Write the controller class

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Myapp extends CI_Controller 
{

    public function __construct()
    {

        parent::__construct();

    }

    /*
    * I am loading the Myapp_model class in the method 
    * index() and not in the contructor
    */

    public function index()
    {

        /*
        * this load the application/models/Myapp_model.php.
        * once the model class is loaded, it is automatically instantiated and this is the reason I don't want it loaded in the constructor. 
        */

        $this->load->model('Myapp_model');

        ## we prepare the output as an array

        $data['content'] = array($this->Myapp_model->set_index(), $this->Myapp_model->another_content());

        /*
        * this will load the application/views/Myapp_view.php
        * we assign the data array to the view file 
        */
        $this->load->view('Myapp_view', $data);

    }

}

/* End of file Myapp.php */
/* Location: ./application/controllers/Myapp.php */

3.** Create the model class for the controller**

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Myapp_model extends CI_Model 
{

    public function __construct()
    {

        parent::__construct();

    }

    /*
    * if you look closely on the controller class above, 
    * $data['content'] has been given the value of this model method
    */

    public function set_index()
    {

        $paragraph = '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>';

        return($paragraph);

    }

    public function another_content()
    {
        $paragraph = '<h2>From another_content() method </h2><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>';

        return( $paragraph );
    }

}

 /* End of file Myapp_model.php */
/* Location: ./application/models/Myapp_model.php */
  1. Load only the view that is relevant to the route request. Meaning, we don't want to assign data to any forward looking template file. Except, when we are using template engine like the twig, smarty and others where template enheritance is supported.

create the view file : application/views/Myapp_view.php

<!DOCTYPE html>
<html lang="en">

<title>Myapp view page </title>

<body>
<h2> This is my first application</h2>

    <?php 

        foreach($content as $p){

            echo $p;
        }

    ?>

</body>

</html>

we can also use the CI suggested syntax for foreach like this

<?php foreach ($content as $p): ?>

<?=$p?>

<?php endforeach; ?>

However, I am not a big fan of a short tags.

5. Define your routes. Although it may not be necessary, because of the naming convention I used for the controller, CI is smart enough to find it. I will still give you the example of the routes for the above controller.

application/config/routes.php

$route['myapp'] = 'myapp';

the url for the above will be something like this

http://localhost/index.php/myapp

the url content will remain to be true, even if we don't create a route for it, because CI will look for the Myapp controller class in the application/controllers/ directory. So, it is pretty easy to write an application in CI.

The only time a route is needed if we are to change the url to something different than the controller class name and method

for example

$routes['something'] = 'myapp';

the above routes will respond to a uri request for localhost/index.php/something and deliver the output of the myapp controller.

we can also create another method on the controller that can respond to a different request.

public function different_request()
{

    $data['different'] = $this->Myapp_model->diff_request();
    $this->load->view('Diff_view', $data);

 }

we add the diff_request() method to the Myapp_model

public function diff_request()
{

    return ('hello from the diff_request method of the Myapp model class');

 }   

We can then create another route specific only to the different_request method

 $route['different'] = 'myapp/different_request';

the above will respond to uri request for

localhost/index.php/different

Without the routes, we can send our request with this not so secure convention

localhost/index.php/controller_class_name/controller_class_name_method

Disclosures and Warnings!

In production server, make sure to use routes different than the controller class name. There is a bad implications to this. You can search for Phil Sturgeon's article entitled Beware the Route to Evil, but this is for another time discussions.

What really matters now is to have you immersed ASAP on how the CI framework does its job.

commented: Great advice, clearly a lot of effort gone into that +6

@veedeoo, it is a very nice building block.

I think I already basic CI. I have learned CI for a few months before. I just haven't been able to create a simple CMS. Now, I think I decide to use ready-to-use CI template which is provided in the tutorial called Structure-Core. First I need to get at least the error fixed.

_output_footer.php

<div id="footermainPan">
    <div id="footerPan">
      <?=$this->Mediatutorialmenu->menu_bottom()?>
      <?
      $site_details = $this->Mediatutorialheader->site_details();
      $structure_core = $this->Mediatutorialheader->structure_core();
      //
      $powered = $structure_core['name'].' '.$structure_core['ver'].' build '.$structure_core['build'].' - '.$structure_core['coding'];

      ?>

      <p class="copyright"><?=$this->Mediatutorialheader->copyRight($structure_core['year'])?></p>
      <p class="powered">Powered by <?=$powered?> </p>
    </div>
</div>

models/mediatutorialheader.php

class Mediatutorialheader extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }

    function structure_core(){
        $structure_core = array(
            'name'  => 'Structure_core',
            'ver'   => '1.2',
            'build' => '1',
            'release'   => '7 September 2011',
            'coding'    => 'Codeigniter 2.0.2',
            'dir_root'  => 'C:/xampp/htdocs/CI-202-StructureCore/',
            'domain'    => "http://{$_SERVER['SERVER_NAME']}",
            'year'      => '2014'
        );

        return $structure_core;
    }

    function site_details(){
        $table_name = array();
        $table_content = array();

        $this->load->database();
        $query = $this->db->query("SELECT * FROM `options`");
        $row = $query->row_array();
        foreach ($query->result_array() as $row)
        {
           array_push($table_name, $row['name']);
           array_push($table_content, $row['content']);
        }
        return array_combine($table_name, $table_content);

    }

    //copyright
    function copyRight($year) {
        $current = date('Y');
        if($year == $current) { $eyear = $year; }
        else { $eyear = "$year - $current"; }
        return "All content &copy; $eyear";
    }
}
?>

Error messages:

Mediatutorialheader->site_details(); $structure_core = $this->Mediatutorialheader->structure_core(); // $powered = $structure_core['name'].' '.$structure_core['ver'].' build '.$structure_core['build'].' - '.$structure_core['coding']; ?>

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: structure_core

Filename: views/_output_footer.php

Line Number: 13
All content © - 2014

Powered by
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: powered

Filename: views/_output_footer.php

Line Number: 14

------------------------------------

Line 13 - 14:

<p class="copyright"><?=$this->Mediatutorialheader->copyRight($structure_core['year'])?></p>
      <p class="powered">Powered by <?=$powered?> </p>

How to fix this error?

I have another error appears:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$structure_core

Filename: core/Model.php

Line Number: 50

Line 27 - 52:

system/core/Model.php

class CI_Model {

    /**
     * Constructor
     *
     * @access public
     */
    function __construct()
    {
        log_message('debug', "Model Class Initialized");
    }

    /**
     * __get
     *
     * Allows models to access CI's loaded classes using the same
     * syntax as controllers.
     *
     * @access private
     */
    function __get($key)
    {
        $CI =& get_instance();
        return $CI->$key;
    }
}

Line 50: return $CI->$key;

How to fix the error?

The purpose of my example is to realize the core principle of MVC design Patterns which is no other than the "Separation of Concerns". All PHP MVC and HMVC frameworks follow this core principle.

In a personal level, I have nothing against the author of the tutorial that you are following. However, things that are meant to be confined in the controller and in the model should not be found in the view files.

Codes below are wrong

    <div id="footermainPan">
    <div id="footerPan">
    <?=$this->Mediatutorialmenu->menu_bottom()?>
    <?
    $site_details = $this->Mediatutorialheader->site_details();
    $structure_core = $this->Mediatutorialheader->structure_core();
    //
    $powered = $structure_core['name'].' '.$structure_core['ver'].' build '.$structure_core['build'].' - '.$structure_core['coding'];
    ?>
    <p class="copyright"><?=$this->Mediatutorialheader->copyRight($structure_core['year'])?></p>
    <p class="powered">Powered by <?=$powered?> </p>
    </div>
    </div>

Even if the view carries an instance of the model, there is no way we can pass those data effeciently. Since the model if pretty mal-formed, expect to have an error in teh core/model.

**The reasons?: ** There must be an intance of this model, We want to take advantage of the protection provided by the helpers and libraries and most of these things must be called or instantiated in the Controller.

 Mediatutorialheader

For another chance, please allow me itimized the weakness of the source codes. If we are to follow the basic principles of MVC, then models/mediatutorialheader.php class must be instantiated by the controller/s. It does not matter how many controllers, as long as the data from the model passes the controller, so that the burden of concern on the model ends when any method returns something. This data will then be pick-up by the controller and assign them to the view file.

**Here are my reasons why the tutorial does not adhere to the simple rules of MVC design patterns. **

Models should not be allowed to directly send output to the view. CI is the loosest MVC framework we can find and it is not even strict in so many ways. In fact, we can pretty much bypass the model and give the responsibilities to the controller. BUT, there is a pretty big BUT, we don't want to abuse the looseness of such framework. What I meant by this is that, there must be controller and view. This is the maximum we can tolerate when it comes to cutting corners.

Models is pretty much responsible for carrying sensitive operations of the application, mainly accessing data from the database and then send it to the controller per request of the user. Considering the severity of this responsiblity, we cannot allow any communication between the model and the view.

as shown on your codes

 <?=$this->Mediatutorialmenu->menu_bottom()?>
<?
$site_details = $this->Mediatutorialheader->site_details();
$structure_core = $this->Mediatutorialheader->structure_core();
?>

this might be valid, but please don't do it. It is so easy to develop a bad habit in naming variables.

 function structure_core(){

    $structure_core = array(
    'name' => 'Structure_core',
    'ver' => '1.2',
    'build' => '1',
    'release' => '7 September 2011',
    'coding' => 'Codeigniter 2.0.2',
    'dir_root' => 'C:/xampp/htdocs/CI-202-StructureCore/',
    'domain' => "http://{$_SERVER['SERVER_NAME']}",
    'year' => '2014'
    );
    return $structure_core;
    }

the method's name is re-used as variable name. If not careful, this can accidentally result in a pointless recursion.

this error here

Error messages:

Mediatutorialheader->site_details(); $structure_core = $this->Mediatutorialheader->structure_core(); // $powered = $structure_core['name'].' '.$structure_core['ver'].' build '.$structure_core['build'].' - '.$structure_core['coding']; ?>

occured, because the view don't even know that those variables exists. It has to be passed from the model to the controller and ultimately to the view file.

This error

Line 50: return $CI->$key;

is caused by a mal-formed codes which is more likely on your model. I have a means of suppressing it, but it is not wisest thing to do at this time. The model and the controller must be written in well formatted class.

What I can suggest in regards to all of these inconsistencies on your code is to remove the objects of the Mediatutorialheader from the view and assign them in the controller.

Again using the basic syntax and convention, you must do it like this. It does not matter if it is a different method.

/*
* method index can be something else
*/

public function index()
{
    $this->load->model('Mediatutorialheader');
    $data['header'] = $this->Mediatutorialheader->structure_core();
    $this->load->view('Name of the template for this controller',$data);
 }

you can then iterate the header array in your template file. You can also have a separate template file for the header if you want included in the main template file.

again the iteration is pretty much the same as my basic example above.

foreach($header as $item=>$value){
    // will give you the items from the array $data['header'] provided by the model class method called structure_core()
    }

I will come back to this thread and tell you more about your codes later. I just feel very exhausted to this point. It is just too much cover to put your application on the right track.

I am trying to fix this error:

    Error messages:
    Mediatutorialheader->site_details(); $structure_core = $this->Mediatutorialheader->structure_core(); // $powered = $structure_core['name'].' '.$structure_core['ver'].' build '.$structure_core['build'].' - '.$structure_core['coding']; ?>

I add: $this->load->model('Mediatutorialheader');

right after index()

controllers/welcome.php

class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library(array('session'));
        //
        $model_available = array('Mediatutorialauth', 'Mediatutorialmenu');
        $model_header = array('Mediatutorialheader');


        if(file_exists( 'application/models/mediatutorialheader.php'))
            $model_available = array_merge($model_available, $model_header);

        $this->load->model($model_available);

    }

    function index()
    {
        $this->load->model('Mediatutorialheader');

        if ( !file_exists( "application/models/mediatutorialheader.php" ) )
        {
            //dynamic page -  send headers to do not cache this page
            $now = gmdate('D, d M Y H:i:s') . ' GMT';
            header("Expires: $now");
            header("Last-Modified: $now");
            header("Cache-Control: no-cache, must-revalidate");
            header("Pragma: no-cache");

            echo "Maap, StructureCore anda <b>belum terinstall</b>\n";
            if ( file_exists( "install/index.php" ) ) {
                echo "Mohon tunggu kami akan mendirect ke halaman installasi<br />\n";
                echo "<script language=\"Javascript\">location.href = 'install/index.php';</script>\n";
            }
            exit;
        }

        if ( file_exists( "application/models/mediatutorialheader.php" ) &&  file_exists( "install/index.php" ))
        {
            $data['structure_core'] = $this->Mediatutorialheader->structure_core();
            $this->load->view('_installed', $data);

        }
        else{
            $site_details = $this->Mediatutorialheader->site_details();
            $data = array(
                'title' => $site_details['site_title'],
                'body' => $this->promo()
            );
            $this->load->view('_output_html', $data);
        }
    }

    function promo(){
        $site_details = $this->Mediatutorialheader->site_details();
        /*$data = array( //nah, ini fungsi asli
            'title' => $site_details['site_title'],
            'description' => $site_details['site_description']
        );
        */

        $data = array( //KALO INI CUMAN COBA COBA
            'title' => 'Selamat datang di Structurecore versi Codeigniter!',
            'description' => 'Ini merupakan Social Network yang 100% free and opensource, ajax and jquery, chat, wall, profile, notifications, forum, module, administration and many more',
            'container' => $this->load->view('_1_coba_profile_pic', '',true)
        );

        return $this->load->view('_promo', $data, true);
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

I wonder why the error still remains?

routes.php

$route['default_controller'] = "welcome";

Whenever I try to open the mainpage.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.