Welcome Guest, Not a member yet? Register   Sign In
How to call a controller from another controller ?
#10

[eluser]Twisted1919[/eluser]
[quote author="WishBear*" date="1297967386"]@Twisted1919: Doesn't my suggestion answer his question? from the categories controller he will pass the result to the blog controller and load that result to the blog container view?[/quote]

You say:
Code:
class Blog extends CI_Controller {
    
    function __construct()
    {
            parent::__construct();
    }
    
    function index()
    {
            $data['categories'] = $this->load->view('category/list', null, TRUE);

            $this->load->view('container', $data);
        }
}
So you assign a view to a variable, right ? IE:
$data['categories'] = $this->load->view('category/list', null, TRUE);
BUT you don't pass the categories to the view.
Assuming that in the loading view, there is a foreach($categories AS $cat) loop going through categories and echo them one by one, in your method, this will error, because the $categories is undefined.
Do you understand my point here ?

In order to make it function, you would need something like:
Code:
class Blog extends CI_Controller {
    
    function __construct()
    {
            parent::__construct();
    }
    
    function index()
    {
            // get the blog categories and assign them to a variable
            $this->load->model('categories_model','cat');
            $categories=$this->cat->get_categories();
      
            $data['categories'] = $this->load->view('category/list', array('categories'=>$categories ), TRUE);
            // now, the category/list view can use the foreach() as stated above.
            $this->load->view('container', $data);
    }
}


Messages In This Thread
How to call a controller from another controller ? - by El Forum - 02-16-2011, 10:04 AM
How to call a controller from another controller ? - by El Forum - 02-16-2011, 10:25 AM
How to call a controller from another controller ? - by El Forum - 02-16-2011, 10:37 AM
How to call a controller from another controller ? - by El Forum - 02-16-2011, 12:43 PM
How to call a controller from another controller ? - by El Forum - 02-16-2011, 03:27 PM
How to call a controller from another controller ? - by El Forum - 02-16-2011, 05:41 PM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 06:04 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 06:29 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 06:58 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 07:01 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 07:02 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 07:09 AM
How to call a controller from another controller ? - by El Forum - 02-17-2011, 08:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB