Calling method inside controller from view |
[eluser]huzzi[/eluser]
I like to know how to call a method inside a controller from a view, I don't want to put it inside a helper or in the model. eg: Code: class Homepage extends MY_Controller { Then, inside the view. Code: <html> I tried the above but I get error Fatal error: Call to undefined method CI_Loader::viewBasket() Please help.
[eluser]huzzi[/eluser]
[quote author="n0xie" date="1266990291"]Use the Search[/quote] Thanks... i did search but this didn't come up.
[eluser]Zeeshan Rasool[/eluser]
<?=$this->viewBasket()?> to <?=$this->homepage->viewBasket()?> but its not good way of calling method . call functions living inside your controller
[eluser]n0xie[/eluser]
[quote author="Zeeshan Rasool" date="1267024672"]<?=$this->viewBasket()?> to <?=$this->homepage->viewBasket()?> but its not good way of calling method . call functions living inside your controller[/quote] That doesn't work.
[eluser]SpooF[/eluser]
Gather all your data in the controller, pass it to the view and then render your page there. I dont see why you would want to call a method of your controller in your view.
[eluser]Zeeshan Rasool[/eluser]
[quote author="n0xie" date="1267026067"][quote author="Zeeshan Rasool" date="1267024672"]<?=$this->viewBasket()?> to <?=$this->homepage->viewBasket()?> but its not good way of calling method . call functions living inside your controller[/quote] That doesn't work.[/quote] Oh sorry, i thought you need to call a func from model in the view. Why you need this calling you can call model function in the view ( Although its not good approach) but there is no meaning of calling controller function in view ![]()
[eluser]ascotan[/eluser]
[quote author="SpooF" date="1267026308"]Gather all your data in the controller, pass it to the view and then render your page there. I dont see why you would want to call a method of your controller in your view.[/quote] This. Your view should not call the controller. This is what is technically known as "a$$backwordsness". You controller file should collect all your data from the model it needs to render, then pass that data to the view. The view will then render that data.
[eluser]developer10[/eluser]
[quote author="ascotan" date="1267132822"][quote author="SpooF" date="1267026308"]Gather all your data in the controller, pass it to the view and then render your page there. I dont see why you would want to call a method of your controller in your view.[/quote] This. Your view should not call the controller. This is what is technically known as "a$$backwordsness". You controller file should collect all your data from the model it needs to render, then pass that data to the view. The view will then render that data.[/quote] that is like that in theory. what would you suggest in a situation when i need to forach some records which come from the same table. But, when displaying the data, i need to catch lets say, value of ID and to use it for displaying count of rows from some other table. i struggled for a long time in order to achieve that via using arrays but to no avail. Would you agree that using of Code: echo $this->bids->countBids($value['project_id']); is a suitable solution for getting count when in loop?
[eluser]techgnome[/eluser]
I'd loop through the data, and use the ID to get more info, then using the ID as the key, add the returned data to an array... all in the model... from the view, it *should* be as simple then as echo $bidcounts[$projectid] -- if it's a single value ... or echo $moredata[$projectid]->bidcount ... at least that's how I'd start off... seems to make sense to me. -tg |
Welcome Guest, Not a member yet? Register Sign In |