Advice Needed - Using Libraries instead of Controllers to deliver pages |
[eluser]haydenp[/eluser]
In a current project I have to deal with database-driven pages and library-driven pages. I would like advice on whether or not the way in which I deliver the library-driven pages could be done any other "better/more efficient" way? Areas of focus: The way in which the class properties are being handled. The way in which DIRECTORY LIBRARY (A) relies on DIRECTORY LIBRARY (B) ... and any other areas where improvements can be made. Database driven pages All the markup for the page's body comes from the databse Library driven pages All the markup for the page's body is generated by a library (these libraries may depend on other libraries). To cater for the above scenario I have set up a single base controller 'application/controllers/page.php' and route all requests through the 'page/index' method. This allows me to determin if the current page is a database or library driven page based on what is in the url. I am then able to set the class properties and deliver the correct type of page. For example: mysite.com/index.php/terms This would result in a database-driven page being delivered mysite.com/index.php/directory This would result in a library-driven page being delivered ie. the directory library would be loaded and the directory_home() method executed mysite.com/index.php/directory/categories This would result in a library-driven page being delivered ie. the directory library would be loaded and the directory_categories() method executed I currently have it all working but would like advice on whether or not the way in which I deliver the library-driven pages could be done any other "better/more efficient" way? Sample Code: CONTROLLER application/controllers/page.php Code: class Page extends Controller DIRECTORY LIBRARY (A) application/libraries/directory/directory_pages.php Code: class directory_pages DIRECTORY LIBRARY (B) application/libraries/directory/directory_methods.php Code: class directory_methods
[eluser]stuffradio[/eluser]
I don't even see any views being used, you're breaking the MVC pattern and using something like MLC (Model Library Controller). You can keep your Page controller, and perhaps you should also use routes. That way you could go http://yoursite.com/Page/home In your controllers, it would go to the routes, and take the second URI segment. This would be something like Page/index/$1 in your route. Then in the controller, you can check if this is a page that you have defined as needing the database, if yes then do your database stuff, if no then use libraries or however you're doing it now.
[eluser]haydenp[/eluser]
Thanks for the reply stuffradio To keep the lines of code to a minimum I left out view requests etc. The code provided is simply sample code use to try get my point across without overly complicating things. My attempt to keep the post less complex may have backfired? I have edited the sample code to show where the view are being loaded etc. see my controller 'page/index' |
Welcome Guest, Not a member yet? Register Sign In |