Welcome Guest, Not a member yet? Register   Sign In
Headers, Footers, Menu (jedd approach) - the saga continues.
#1

[eluser]squeakita[/eluser]
I am a complete newbie, please forgive any stupid questions.

I am trying to setup this approach for the header/footer/menu.

Here is the error I am getting:

Code:
Message: Undefined variable: main_menu_view
Filename: views/template.php
Line Number: 14

here is MY_controller
Code:
class  MY_Controller  extends  Controller  {

    function MY_Controller ()  {
        parent::Controller();
          $tmp_data['menu_data'] = $this->_generate_menu_data();
          $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $tmp_data, TRUE);
        }


         private function  _generate_menu_data ()
          {
            $menu_data_array = array (
                        "Lobby" => array (
                            "Front page"              => "meta/lobby",
                            "About this site"         => "meta/about",
                            ),
                        "Messaging" => array (
                            "Public Forums"           => "forum",
                            "Private Mail"            => "mail/inbox",
                            )
                                     );

        /// Otherwise, the boring ol' menu gets delivered.
            return ($menu_data_array);
            }
}

Here is the template view:
Code:
<html>
    <head>
    <title><?= $title ?></title>
    <link rel="stylesheet" href="<?=base_url();?>assets/style.css" type="text/css" />
</head>
<body>
    <div id="container">
    <div id="header">
        <h1>
            Site name
        </h1>
    </div>
    <div id="navigation">
     &lt;?= $main_menu_view;  ?&gt;
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>
    </div>
    <div id="content-container1">
        <div id="content-container2">
            <div id="section-navigation">
                <ul>
                    <li><a href="#">Section page 1</a></li>
                    <li><a href="#">Section page 2</a></li>
                    <li><a href="#">Section page 3</a></li>
                    <li><a href="#">Section page 4</a></li>
                </ul>
            </div>
            <div id="content">&lt;?= $contents ?&gt;</div>
            <div id="aside">
                <h3>
                    Aside heading
                </h3>
            </div>
            <div id="footer">
                Copyright © Site name, 20XX
            </div>
        </div>
    </div>
</div>

&lt;/body&gt;
&lt;/html&gt;

Here is the controller I am trying to test it on: blog
Code:
class Blog extends MY_Controller {
    function Blog()
    {
         parent::MY_Controller();
    }

    function index()
    {
        $this->load->model('blogmodel');
        $data['title'] = "My Real Title";
        $data['contents'] = "Lorem ipsum dolor sit amet, consectetur adipisicing ";
        $data['heading'] = "My Real Heading";
        $data['session_id'] = $this->session->userdata('session_id');
        $this->load->view('template', $data);
    }

}
and one last the view : create_table_main_menu , just junk right now - I am just looking to see something.
Code:
<h1>boo!</h1>


Please help, what am I missing? I think once the light goes off, I should be able to code quickly. But I always stumble initially to understand the entire picture.
I am just so use to doing it the way I'e done it for 10 years, I didn't have to think.
Now I have to think - this seems very foreign to me.. :bug:

Thank you for your time!
#2

[eluser]Mischievous[/eluser]
ummm... try doing:
Code:
class MY_Controller  extends  Controller  {

    var $data;

    function MY_Controller ()
    {
        parent::Controller();
          $this->data['menu_data'] = $this->_generate_menu_data();
          $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $tmp_data, TRUE);
        }

         private function  _generate_menu_data ()
          {
            $menu_data_array = array (
                        "Lobby" => array (
                            "Front page"              => "meta/lobby",
                            "About this site"         => "meta/about",
                            ),
                        "Messaging" => array (
                            "Public Forums"           => "forum",
                            "Private Mail"            => "mail/inbox",
                            )
                                     );

        /// Otherwise, the boring ol' menu gets delivered.
            return ($menu_data_array);
            }
}

Code:
class Blog extends MY_Controller {
    function Blog()
    {
         parent::MY_Controller();
    }

    function index()
    {
        $this->load->model('blogmodel');
        $this->data['title'] = "My Real Title";
        $this->data['contents'] = "Lorem ipsum dolor sit amet, consectetur adipisicing ";
        $this->data['heading'] = "My Real Heading";
        $this->data['session_id'] = $this->session->userdata('session_id');
        $this->load->view('template', $this->data);
    }

}
#3

[eluser]squeakita[/eluser]
Thank you, for helping - I continue to get the same error.

I took what you have and tinkered a bit, as I was getting an error with

Undefined variable: tmp_data

Here is what I have working.
Code:
class MY_Controller  extends  Controller  {

    function MY_Controller ()
    {
        parent::Controller();

          $tmp_data['menu_data'] = $this->_generate_menu_data();
         $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $tmp_data, TRUE);
     }

         private function  _generate_menu_data ()
          {
            $menu_data_array = array (
                        "Lobby" => array (
                            "Front page"              => "meta/lobby",
                            "About this site"         => "meta/about",
                            ),
                        "Messaging" => array (
                            "Public Forums"           => "forum",
                            "Private Mail"            => "mail/inbox",
                            )
                                     );

        /// Otherwise, the boring ol' menu gets delivered.
            return ($menu_data_array);
            }
}

Code:
class Blog extends MY_Controller {
    function Blog()
    {
         parent::MY_Controller();
    }

    function index()
    {
        $this->load->model('blogmodel');
        $this->data['title'] = "My Real Title";
        $this->data['contents'] = "Lorem ipsum dolor sit amet, consectetur adipisicing ";
        $this->data['heading'] = "My Real Heading";
        $this->data['session_id'] = $this->session->userdata('session_id');
        $this->load->view('template', $this->data);
    }

}

I do not understand enough yet to determine if this will create limitations in the future.
But it is nice to have this little piece working - Again Thanks.
#4

[eluser]InsiteFX[/eluser]
May be PHP open short tags are turned off!

InsiteFX
#5

[eluser]tonanbarbarian[/eluser]
Undefined variable: tmp_data is because you have not defined $tmp_data as an array but are treating it as such

either of these 2 following options would fix the issue
Code:
class MY_Controller  extends  Controller  {

    function MY_Controller ()
    {
        parent::Controller();

          $tmp_data = array('menu_data' => $this->_generate_menu_data());
         $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $tmp_data, TRUE);
     }

or
Code:
class MY_Controller  extends  Controller  {

    function MY_Controller ()
    {
        parent::Controller();
          $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $this->_generate_menu_data(), TRUE);
     }

you should really declare $this->data as an array as well

Code:
class MY_Controller  extends  Controller  {

    var $data = array();

    function MY_Controller ()
    {
        parent::Controller();
         $this->data['main_menu_view'] = $this->load->view ('create_table_main_menu', $this->_generate_menu_data(), TRUE);
     }
#6

[eluser]squeakita[/eluser]
thank you for the help!
#1 Short Tags are turned on and working - thanks for the pointer.

#2 By declaring that variable in the My_controller, it is the always declared as long as I am using MY_Controller, is that correct?

In other words, declare it in one place and use it through out the application?

Thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB