![]() |
CI2.0 - View files in third_party packages - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: CI2.0 - View files in third_party packages (/showthread.php?tid=32127) |
CI2.0 - View files in third_party packages - El Forum - 07-13-2010 [eluser]JasonS[/eluser] I found that I required view files in packages. To do this I extended the loader file. The changes are pretty simple. This extension does the following. 1) Creates a new class variable _ci_view_paths 2) Add's the default APPPATH to the above array. 3) _add_package_path is extended to add the custom path to the _ci_view_paths variable. 4) As usual the _ci_load function does its thing. Before throwing the 'file not found' error we loop through the _ci_view_paths array to check third_party paths. I would greatly appreciate any feedback on what could be improved. Changes Marked with a comment. //++ Code: <?php CI2.0 - View files in third_party packages - El Forum - 07-13-2010 [eluser]WanWizard[/eluser] I have made the same change to support views. I added support for controllers as well. So far it works without problems. The only issue with packages in general that I still have is the lack of namespace. I use packages to implement modularity without having to resort to HMVC, matchbox, etc. Works fine, but if you use multiple packages, filenames must be unique across packages, otherwise the wrong file will be loaded. I'm currently trying to figure out a way to deal with this, using the module folder name as a sort of 'namespace'. CI2.0 - View files in third_party packages - El Forum - 07-14-2010 [eluser]Buso[/eluser] [quote author="WanWizard" date="1279105084"]I have made the same change to support views. I added support for controllers as well. So far it works without problems. The only issue with packages in general that I still have is the lack of namespace. I use packages to implement modularity without having to resort to HMVC, matchbox, etc. Works fine, but if you use multiple packages, filenames must be unique across packages, otherwise the wrong file will be loaded. I'm currently trying to figure out a way to deal with this, using the module folder name as a sort of 'namespace'.[/quote] I added support for controllers too but only for one package (my 'common' package, which I use as a fallback for everything) Using packages as a way of modularize CI isn't slow? If you have 10 active packages, each time you ask for 'somefile.php', it will iterate over an average of 5,5 packages. Then we have to multiply that by the amount of files you need. I don't know much about optimization anyway, so I may have said something stupid ![]() CI2.0 - View files in third_party packages - El Forum - 07-14-2010 [eluser]pbreit[/eluser] I suppose it's conceivable this could be cached. But, yes, I wonder if there's much a performance hit (for what is a cool feature). CI2.0 - View files in third_party packages - El Forum - 07-14-2010 [eluser]WanWizard[/eluser] Still working on that. The issue with simply iterating over directories is not only performance (which on linux is not too bad, as results of stat calls are cached ), but also the issue of namespace. Two modules can have a library called "test". Which one to load? At the moment I pass the name of the module as parameter to the various load methods, and add this at the top of the path stack. So providing I have not made a typo, the first file_exists() hits. First impressions are that packages to nice to introduce multiple directories for libraries, etc. But it is just that. All restrictions you have with a single directory still apply. |