I have to put a shopping cart on several pages on my ecommerce website (CodeIgniter, MVC Paradigm).
I don't really want to call the model behind this widget in all my controllers.
I know that a solution may be calling the model in the autoloader, but, sometimes, i don't want to display the shopping cart.
So, the solution may be calling the model in the related view. But, since it respect (i think) the MVC paradigm, i'm afraid that CodeIgniter is not really designed like that.
What is the best solution, for keeping a clear, simple and maintenable architecture ?
Thanks !
Hook: you can try to create a Hook that reads/calculates shopping card info and set it to run 'post_controller'
. This way your hook will run after every controller, setting the cart information on session or a flash var to be accessible from your view.
more info here: http://ellislab.com/codeigniter/user-guide/general/hooks.html
alternatively you can call helpers from your View, this is not recommended but it will work.
Place the query code for the cart data in a cart_helper.php
and call it from your view as your would call any other function.
Remember that your helper must be loaded at the time, so either autoload it or set a load on your controller __construct()
You can create a own controller and extend the CI controller and then load the model based upon the conditions.
Here is the reference : http://ellislab.com/codeigniter/user-guide/general/core_classes.html
how about call cartData via ajax request ?