![]() |
How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view (/showthread.php?tid=32380) |
How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 07-21-2010 [eluser]design_shuffle[/eluser] Hi, I have been tearing my hair out over this for about 3 hours, please can someone help? Here is what I want to achieve... On my home page I wish to have a sidebar widget/module which displays the latest 10 events from the events controller. I started off trying to use the widget plugin, but could not get my head around it -Plugin widget Next I read about extending the standard controller to MY_Controller, so in the MY_Controller I added the code from my events controller which retrieves the latest events using the events model, I presume this is the correct place to put this? ##contents of MY_Controller Code: function home_events() Next in my home view I try and load the home_events_view with the following - Code: <?php echo $home_events_view; ?> When I load the homepage I get the following error - Message: Undefined variable: home_events_view Filename: views/home.php Have I approached this the correct way?, can anyone spot where I have gone wrong? Im guessing that I need to put something in my home controller to retrieve the events data? Any help would be appreciated, I have learnt so much lately about codeigniter and I love it, but embedding views has been a big snag! Thanks Dan How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 07-21-2010 [eluser]slowgary[/eluser] It seems fairly straightforward, unless I'm missing something... Code: function home() Then in page.php... Code: <div id='content'> How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 07-21-2010 [eluser]KingSkippus[/eluser] I don't know if this is a best practice (or directly conflicts with a best practice...), but what I would typically do is have a separate widget view, and load it in the controller before the rest of the content. So my controller functions usually end up looking something like: Code: public function index() { How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 07-22-2010 [eluser]lexusgs430[/eluser] It sounds like what you want is modularity, check this library out. http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/ And that is one hell of a controller, from what Ive come to understand about MVC (ive only been really figuring it out for past 2 months so correct me if im wrong smart ppl), you almost always want to try and use skinny controller, fat model/view design. Think of the controller as the guy with the glowing sticks, pointing to the pilot of the plane to guide him. The traffic control tower is the model, plane/pilot are the view. Glowing stick guy has a very important job, without him, the plane will not line up on the runway in the exact right direction, and everyone on board could die. But, if the glowy stick guy were given additional instructions from either the plane or the control tower beyond "hold these glowy sticks and guide the plane for takeoff", he probably wouldnt know what the hell they were talking about, because they would be using fancy flying terms that he doesen't understand. I think the same is the concept of MVC, and ive noticed the smaller my controllers are, and the less touching the data they do directly, the more reusable and efficient, and understandable things become. How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 07-22-2010 [eluser]design_shuffle[/eluser] [quote author="slowgary" date="1279766503"]It seems fairly straightforward, unless I'm missing something... Code: function home() Then in page.php... Code: <div id='content'> Thanks, this worked! It looks like I was trying to over complicate things! How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 10-02-2010 [eluser]insub2[/eluser] ...sorry to resurrect a "solved" thread but... I was wondering if you wanted the events on every page, using this solution you'd need to put those lines of code in every method of every controller? Or is there is another, better, leaner way to do that? How to create sidebar widgets/modules i.e. embedding the contents of another controller in a view - El Forum - 10-02-2010 [eluser]insub2[/eluser] ...nevermind. I found it: Creating a sidebar without duplicate code. |