Welcome Guest, Not a member yet? Register   Sign In
Autoloading library after my controller
#1

[eluser]Unknown[/eluser]
Hello!

I'm working on a site with a 3-panel layout. The left and right panels contains dynamic content such as news which is currently autoloaded with a library. The problem is that I'd like to be able to disable some or all of the panel content in some circumstances. I could solve it by using a different "main layout view" not containing for example the right panel, but there must be a better way? Is it possible to have a library loaded say after the currently loaded controller and have a var set telling the library not to do anything?

Thanks for looking;
Fredrik
#2

[eluser]esra[/eluser]
It's possible to invoke a post_controller hook. You might want to browse through the Codeigniter.php file to learn the sequence of hook points (there are several).

However, if you were using something like Coolfactor's proposed View library for CI, you could conditionally control the visibility of a view fragment in your controller based on conditional code. You also could do this using the conventional CI approach mentioned in the user guide, but I found Coolfactor's solution to be much easier from the standpoint of controling many view fragments. If the condition needs to be based on whether the user is logged on or logged off, you could handle that condition just as well using one of the Authentication/Authorization solutions posted on the wiki.
#3

[eluser]Majd Taby[/eluser]
If I understand what you are saying correctly, why don't you add a "visible" field to the db and run your query to only retrieve those modules you want to have viewable
#4

[eluser]esra[/eluser]
[quote author="Zaatar" date="1192912857"]If I understand what you are saying correctly, why don't you add a "visible" field to the db and run your query to only retrieve those modules you want to have viewable[/quote]

Your recommendation is basically what I do myself but make a distinction between a module's view, a reusable block-like view fragment (what I believe is the topic of interest) and a template for file storage and code reuse reasons. This allows those entities to be stored in separate directory structures and promotes better code reuse. I use a registry table to register all CI extensions (modules, blocks, templates, languages, plugins, helpers, libraries, etc.) with a lookup table or enum field for categorizing the various extensions. This table is managed by a dedicated installer module accessed from admin. Using some additional database-centric solutions, it is also possible to add versioning support and dependency tracking. I actually use two flags, one for visibility and another to determine if an entity is a core requirement. The latter flag is used to prevent the installer from removing code it should not remove during uninstallation.
#5

[eluser]Unknown[/eluser]
Thanks a lot for taking your time giving me advice!

I will look into post controller hook and see if I can use that approach to load my libraries.

What I want to have(I will try to make myself a bit more clear Wink) :
As default all "view blocks" in the side panels are shown in every page except for some pages which is set in their respective controller. Say that I have a search page, when the search result is shown I might not want the right panel to be visible and have some relevant search info shown in the left panel.

So if a user visits site.com/search/result don't load 'some libraries'.

I really don't want to do the opposite and load the libraries in every controller, I rather set a var telling the library not to load.


Again, thanks!
Fredrik




Theme © iAndrew 2016 - Forum software by © MyBB