Welcome Guest, Not a member yet? Register   Sign In
Efficiently re-using code
#3

[eluser]Xandrios[/eluser]
Hi Owan, thank you very much for your reply.

While this would probably work, it would still involve requesting (although easier) data for the embedded views. If this has to be done in every controller of which view embeds something, even though it is not much, it feels repetitive.

I was wondering, is it not common for the view to have a reference to the model? In other words: If I create a poll-view, and a poll-model, would it be possible to load the poll-model in the poll-view? (instead of the controller). This way I could include the poll-view in every page I like, and the poll-view could request the specific data from the poll-model itself.

http://upload.xandrios.net/alt_model_idea.png

Would this be a smart solution to the issue? And would it technically be possible? I tried loading a model in a view, but this did not seem to work. However when loading the model in a controller, I was able to access it in the view...

[edit]
I was able to load a Model in a view, using this method:

$CI =& get_instance();
$CI->load->model('Test');
$data = $CI->Test->testFunction();

The documentation however says that it should also work with $this instead of $CI. Unfortunately this doesnt seem to be the case. "$this->load->model('Test');" does not work in the view. Could this be because my view does not include a class declaration?


Messages In This Thread
Efficiently re-using code - by El Forum - 07-06-2007, 01:45 PM
Efficiently re-using code - by El Forum - 07-06-2007, 02:34 PM
Efficiently re-using code - by El Forum - 07-06-2007, 03:08 PM
Efficiently re-using code - by El Forum - 07-06-2007, 07:12 PM
Efficiently re-using code - by El Forum - 07-06-2007, 07:25 PM
Efficiently re-using code - by El Forum - 07-07-2007, 05:50 AM
Efficiently re-using code - by El Forum - 07-07-2007, 06:23 PM
Efficiently re-using code - by El Forum - 07-08-2007, 10:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB