Partial Views (i think).. |
[eluser]Korhal[/eluser]
Hi guys, I posted a thread a few days back but it didn't take the direction I was looking for, so I will try again and fingers cross explain a little better. I have a list of controllers.. Home, League, Forum as so on. Once the controller has its data it calls down to a view named template which in turn calls the default header, footer, content and sidebar views. (The content variable is set by the controller). So far so good, this works great until I realise the need the sidebar data to be dynamic instead of its current static state.. Now as the site grows larger I would prefer not to have to specify the data that gets called for the sidebar each time. I would prefer to set a variable in the controller that loads "widgets" possibly, I see this being done in the template view, however I know controllers can not be called in view, so I am stuck. $sidebar = array('latest_news','latest_forum'); Currently I am emulating this affect with Ajax... I specify a list of variables in the controller. The template loops the variables and does an Ajax request for each required widget, pushing them into a div.. There must be a better way... Example: http://dev.banelingnest.com/ Now i have looked at HMVC and i cant wrap my head around it. It rather seems bloated for my limited requirements. Does anyone have a nice and simple way of achieving this? Thanks in advance.. Korhal
[eluser]osci[/eluser]
Well HMVC is not bloated. And you will be able to just do a modules::run(). Setting it up isn't tedious at all. You just have to change your controller to extend MX instead of CI and create folders there are in application in a subfolder modules Just folders like modules/module_name/controllers/ modules/module_name/models/ modules/module_name/views/ modules/module_name/languages/ etc
[eluser]Korhal[/eluser]
I dont understand why i need modules when all i need is simple bits of code.. $this->news_model->get_data(5); // Display it in a few lines of HTML.. The models are already build in the normal method.. ?
[eluser]osci[/eluser]
Well HMVC instead of MVC is much better and you'll see the need of it in greater scale application (although small ones benefit too through it's modularity.) You can of course have a simpler solution check User Guide - Views Example. You should use a base controller to have it usable by extended controllers for that (read User Guide - Creating Core System Classes about extending and search the forum for MY_Controller for a start) Code: $this->load->model('mod1_model');
[eluser]InsiteFX[/eluser]
HMVC also has an addon for Widgets do a search for it! Also for partial views with HMVC you just do this: Code: <?php echo Modules::run('module/controller/method', $param, $...); InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |