Welcome Guest, Not a member yet? Register   Sign In
News and statistics in the left column
#11

[eluser]got 2 doodle[/eluser]
Great glad you have a solution
I tried this and it worked
In parent controller
Code:
function Site_Controller()
        {
        
            // Call parent constructor
            parent::Controller();
        $sample['test_one']="test one";
        $sample['test_two']="test two";
        $this->load->vars($sample);
Next view is called by child controller (home.php in this case)
home.php does not make any reference at all to $sample array or $test_two variable

in view
Code:
<?php echo $test_two ?>

outputs 'test two'

doodle
#12

[eluser]Bikun[/eluser]
Great! It really works. Will use your solution. Thanks a lot.
#13

[eluser]got 2 doodle[/eluser]
We all learn together around here,
your welcome.

doodle
#14

[eluser]sl3dg3hamm3r[/eluser]
I wouldn't mess around too much with globals. Stick to class-members, make data a member:

Code:
class SiteController extends Controller {
    var $_container;
    protected var $data;  // Not sure if 'protected' workes if PHP < 5, if not leave it away


    function SiteController() {
        // Call parent constructor
        parent::Controller();

        $this->data['news'] = $this->db->get('news');
        echo $this->data['news']->num_rows(); // This returns 2 as it should
    }
}

In the child class, you also need to write $this->data...

Not tested, but should work like that...
#15

[eluser]crumpet[/eluser]
you will need to change all your $data vars to $this->data

if there is no $this in front of a variable then it is only registered in the namespace of hte function not hte whole class
you need $this to share it between class functions
Also unless your header and footer are always changing you should set them in the same function as news so you don't have to set them everytime
otherwise your controllers will get cluttered with writing the same code over and over again.

remember the constructor of SiteController runs before the functions so you can always change thigns later
you can just set default values for your templating variables there so you don't have to write as much code




Theme © iAndrew 2016 - Forum software by © MyBB