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

[eluser]got 2 doodle[/eluser]
Great glad you have a solution
I tried this and it worked
In parent controller
function Site_Controller()
            // Call parent constructor
        $sample['test_one']="test one";
        $sample['test_two']="test two";
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
<?php echo $test_two ?>

outputs 'test two'


Great! It really works. Will use your solution. Thanks a lot.

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


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

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

        $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...

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