![]() |
Widgets and Modules ? - 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: Widgets and Modules ? (/showthread.php?tid=30516) Pages:
1
2
|
Widgets and Modules ? - El Forum - 05-17-2010 [eluser]Buso[/eluser] Hi, some days ago I read (or maybe it's just my imagination :down ![]() What I need is something like a userbar, which I can just pass to my view or call it from the view. I want it to have its own logic, like checking if the user is logged in or not, so I don't have to do it from the controller or view that is calling the widget. It seems like I could do that with the widget plugin, but I can't stop thinking about using modules instead of that. Any ideas? Widgets and Modules ? - El Forum - 05-17-2010 [eluser]bretticus[/eluser] There are a number of ways to do things similar to view partials. Not quite sure why modules are needed, but handy all the same. I think, quite possibly, the simplest way to perform the "userbar" scenario is to make use of the vars() method of the loader class. In case you aren't familiar, it is a way to pass an array that is "global" for any view that may happen to get called. With this in mind, it would be trivial to set a variable in each of your views (perhaps $userbar.) You can set it once in the controller and the contents of that variable will be available for each controller which sets it. Code: //controller Widgets and Modules ? - El Forum - 05-17-2010 [eluser]Buso[/eluser] thanks, i know some ways of handling partial views, but what I wanted was 'intelligent partial views' as widgets call themselves. Eg: Code: $data['userbar'] = Widget::userbar(); or Code: $data['userbar'] = $this->load->module('users/userbar') So userbar can have its own logic. Widgets allow you to have your userbar logic stored in widgets/userbar.php and its views in widgets/views/userbar.php (you are supposed to call them from within your views, but I would be happier if I could use them the way I mentioned) And that's cool, but I wont be able to sleep until I find this thing I read somewhere: 'widgets are just like modules, but you can use them as view partials' Widgets and Modules ? - El Forum - 05-17-2010 [eluser]bretticus[/eluser] If it means that much to you, then by all means, go for it. If you want to be able to "sprinkle" these around to various codeigniter installations, modules is the way to go. However, it's not that much more difficult to just have your model handle all the logic (including which views are called for "userbar" content.) It would be a userbar module after all. In other words, I never suggested dumping static HTML into vars(). I'm just suggesting that widgets/modules/doohickies may be more distracting to you than beneficial. Widgets and Modules ? - El Forum - 05-17-2010 [eluser]Buso[/eluser] ok ill try modules (not sure yet if they can be used that way) doing it with a model method wouldn't let me have all the logic for the userbar contained in the same place. A widget should be almost plug & play Widgets and Modules ? - El Forum - 05-17-2010 [eluser]bretticus[/eluser] [quote author="Buso" date="1274171535"]ok ill try modules (not sure yet if they can be used that way) doing it with a model method wouldn't let me have all the logic for the userbar contained in the same place. A widget should be almost plug & play[/quote] Are you actually using Modular Separation? I don't want to discourage anyone from using some elegant way of modularizing code using MS/Matchbox/HMVC/etc. But I do think it's worth stating that most projects do not need "modular separation." I assume you plan on sharing your code with the community perhaps. In that case, yes, modules are a great way to package your code (albeit it relies now upon a module change to CI.) I have no idea what widgets are as they are not a component of MVC nor CodeIgniter, but I know that it's convenient to drop in a plugin that just works. Perhaps widgets are always called by the view method when they exist. I'm just guessing this is functionality of the module code? From my basic perspective of modules, however, you have to refer to them via URL. If I were you I'd find the forum post with the details/documentation for the modules code (Modular Seperation) and after looking for the specific information about "widgets", if you do not find it, ask there. The author most likely follows that post. Good luck! Widgets and Modules ? - El Forum - 05-17-2010 [eluser]Buso[/eluser] sorry, i was talking about this: http://ellislab.com/forums/viewthread/109584/ Anyway if it didn't exists, I could write something similiar as the concept of widget exists in other enviroments such as most CMSs. It's just something draggable and droppable, like modules. I saw that they implemented it in PyroCMS (and velOcira xD - pyro's clon-), for instance. I think ExiteCMS has it too. (all these are codeigniter-based) Widgets and Modules ? - El Forum - 05-17-2010 [eluser]bretticus[/eluser] Just looked through the source for Modular Separation http://codeigniter.com/wiki/Modular_Separation Didn't see any notion of "widgets." Impressive hack. Only two library files that extend CI_Router and CI_Loader. Widgets and Modules ? - El Forum - 05-17-2010 [eluser]Buso[/eluser] sure thing. I thought CI 2.0 was going to have modules out of the box, but it seems like it wont. ps: check the link I posted. Modular Separation and Widgets share the same author Widgets and Modules ? - El Forum - 05-17-2010 [eluser]bretticus[/eluser] [quote author="Buso" date="1274173607"]sorry, i was talking about this: http://ellislab.com/forums/viewthread/109584/ Anyway if it didn't exists, I could write something similiar as the concept of widget exists in other enviroments such as most CMSs. It's just something draggable and droppable, like modules. I saw that they implemented it in PyroCMS (and velOcira xD - pyro's clon-), for instance.[/quote] Yeah, Wordpress has something very similar to this too. Phil may have rolled his own "widgets" knowing him (which I only do by reputation.) Why not extend your view method to look for a widgets folder? Execute whatever is in there? In wordpress it seems like you call a widget function with a param that stipulates which part of the layout you are calling from (sidebar, header, footer, etc.) However, unless you are building a CMS or your own reusable platform, this might be overkill. ![]() I'd be very interested to see what you come up with. |