Welcome Guest, Not a member yet? Register   Sign In
Best way to avoid duplicating html in views
#21

[eluser]Polarity[/eluser]
Yea, i think you cant load a controller inside a controller because it makes no sense. Controllers are for controlling your app and not returning something. Every Controller is also available over the url, so you shouldnt returning any data (except the view).

Instead of using a controller for doing stuff and returning data you can use helpers for plain functions (look at my first example), librarys, hooks or models.
#22

[eluser]mortifrog[/eluser]
ok one last quick reply then off to the land of nod.

Quote:Every Controller is also available over the url
- yes but you can make all of it's functions private by prefixing them with a double underscore can you not?

I can envisage wanting to borrow the logic of one controller within another - but I take on board what your saying about hooks and helpers and stuff. I've not really got that far yet.

I did try this though:

Code:
class Quatermass extends Controller {

    function Quatermass()
    {
        parent::Controller();    
    }
    
    function index()
    {    
    
    include('./system/application/controllers/quatermass2.php');
    $q2= new Quatermass2;
    
    $data['site_name'] = 'Quatermass';
    $data['template'] = 'default';
    $data['content'] = $this->load->view('view_a');
    $data['content'] .= $this->load->view('view_b');
    $data['content'] .= $q2->wow();
    $this->load->view('templates/default/index', $data);
    }
}

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

Code:
<?php

class Quatermass2 extends Controller {
    
    function Quatermass2()
    {
        parent::Controller();    
    }
    
    function wow()
    {    
    $wow = 'Wow!';
    return $wow;
    }
    
}


?>

And it worked, which is pretty useful to know as long as it's not a bad habit to get into.
Don't know why the output returns Wow on a new line though. Goodnight all.




Theme © iAndrew 2016 - Forum software by © MyBB