Welcome Guest, Not a member yet? Register   Sign In
Global controller?
#1

[eluser]Sein Kraft[/eluser]
I've a header that should show the username and another things. But I don't want to declare in every function $this->load->view('header', $data);.

There is ani way to avoid that?
#2

[eluser]jedd[/eluser]
[quote author="Sein Kraft" date="1259913699"]
But I don't want to declare in every function $this->load->view('header', $data);.

There is ani way to avoid that?[/quote]

Yes - but you have to read the [url="/wiki/FAQ"]FAQ[/url].
#3

[eluser]Sein Kraft[/eluser]
I've tried that without luck.

This MY_Controller.php
Code:
<?php

class Users extends MY_Controller {

    function Users()
    {
        parent::MY_Controller();
    }
    
    function my_user()
    {
        return "username";
    }
}
?>

Quote:Fatal error: Class 'MY_Controller' not found in D:\Server\htdocs\system\libraries\MY_Controller.php on line 3
#4

[eluser]Colin Williams[/eluser]
Your MY_Controller.php must define the MY_Controller class. Then, later classes will extend it.
#5

[eluser]Sein Kraft[/eluser]
Thanks, now is working.

But still have the doubt about that because...for example. I need the "global" header but where i put this?

Code:
$this->load->library('parser');

$data = array(
            'username' => $this->username_from_session(),
            'new_messages' => $this->new_messages()
            );

$this->parser->parse('header', $data);

Because I'm putting this on every function and is a bit messy, I want to avoid that.

Should I put that on:
Code:
function Users(){
    
        parent::MY_Controller();
    
}

And then the view for each funcion in the funtion? and whats happend with the footer where I should put it?
#6

[eluser]stuffradio[/eluser]
MY_Controller

Code:
<?php

class MY_Controller extends Controller
{

      function MY_Controller()
      {
          parent::Controller();
       $this->parser->parse('header', $data);
      }

}

Yourcontroller.php

Code:
<?php

class Yourcontroller extends MY_Controller
{

     function Yourcontroller()
     {
        parent::MY_Controller();
     }

     function yourfunction()
     {
       // header loaded first
       $this->load->view('myview');
     }
}
#7

[eluser]Sein Kraft[/eluser]
Thanks, this was very useful.

BBut another question, what happend with the footer?

I should load it like the custom views in functions?
#8

[eluser]stuffradio[/eluser]
Not sure what to do for footers, I personally load the footer underneath the page.

Code:
$this->load->view('myview');
$this->load->view('footer');
#9

[eluser]Sein Kraft[/eluser]
Yep, I was thinking that.




Theme © iAndrew 2016 - Forum software by © MyBB