I am looking at suitable architecture for a Codeigniter based application , the requirement is such that end of the program I must be able to reuse certain modules , completely.
I was looking at a solution like HMVC.
I need to know if this is the best solution for my problem.
To build a set of independent modules that can be reused with minimal changes.
Regards,
Gayan
At what level do you want to reuse "modules"? For example, the models that you create could be reused on a different web application, since they will simply be an interface between your web application and the back-end database.
If you create REST web methods using a framework such as CodeIgniter REST Server, those methods might also be at a suitable level of generality that they could be re-used as well.
I suppose the next question is, do you need and entire 'module' of code that can be copied out of this app and pasted into another one? If that is what you are looking for, then HMVC would be the final piece of the puzzle that you can use to tie everything together - just create this general code within one or more modules.
Does that help at all?
Related
I'm new to Zend Framework 2 and I'm trying to build an application for (so far, moderate) "fun" and I need some hints to know how should I structure my application.
I have a existing module that allows me to display some web pages with 2 controllers and a database access.
My application is aimed to use Git's system commands or the GitHub API or the BitBucket API depending on the situation.
I thought of making a interface that "prototype" my methods and make 3 classes that implements it but I don't know if it is possible with the framework, if it is the best way to do it, if I should create a entirely new module to do so, if I should write those methods in diffrerents controllers or if I would be able to call those methods in my current module.
I would really appreciate if you could either answer my questions or provide my a ressource that could help or at least give me some hints.
Thank you
Your thoughts on using an interface sound like the right approach, assuming you want system/Github/BitBucket to be interchangeable.
The rest of your questions relate to organising your app code, to which there is no 'correct' answer, and you are in the best position to judge this; so do what seems most sensible to you. The only thing I'd say is that if you can forsee wanting to use part of the functionality in another application, or wanting to let other people use it, it might make sense to split that part out into its own module.
This might look like a dumb question but I am new to MVC particularly to extJs. I wish to work with the MVC approach. I followed this link http://www.extjsframework.com/mvc/simple-mvc-application. But it has only a single page as example. The example page uses app.js to load extjs views. Now here is my question. I have an application with multiple pages. Do i need to make separate app.js like scripts for each page of my app or could i use the same app.js accross all my pages. If i could, kindly mention how.
Thanks...
All of the answers here are correct, however the question seems to be a bit ambiguous so that's why they are all slightly different.
The typical RIA app is a single HTML(or php,jsp,asp) page with many different views all managed by the the JS framework, so changing pages is no longer required (and in most cases avoided for performance reasons).
Your server side code/scripts are then typically reduced to JSON data services that provide data to the RIA app running completely independently in the client browser.
As you can see you would not need to have test.php and index.php and would suffice to have one index.php with ExtJS application running out of that page.
If this answer is not useful because you already knew all of this and really meant to ask about multiple controllers and modularization of an ExtJS application then that's a separate discussion and has been addressed to an extent in other posts. (look for lazy loading controllers).
Hope this helps.
Every page. Every time a page unloads, it's like the JS slate gets cleared. The browser will actually cache the files but the code executes like it was the first time.
Usually it's same app.js for all different views.
The MVC concept of ExtJS 4 is about architecture. The documentation clarifies that pretty easily.
Every Ext JS 4 application starts with an instance of Application class. The Application contains global settings for your application (such as the app's name), as well as maintains references to all of the models, views and controllers used by the app. An Application also contains a launch function, which is run automatically when everything is loaded.B
As you can see in the docs, you will have one single app.js, that is gonna be like a bootstrap, responsible to instantiate the whole application.
You are gonna structure your files, however, following the MVC approach, or pattern, in order to have a nice and clean architecture.
i have a project i took over. it is an app that has been build over many years with PHP and mysql.
It currently has a sort of good folder structure but the code itself is very poor written.
There is php, sql statements and html code in almost every file.
There is javascript code generated using php echo for not reason and so on.
I will like to use for further development either CakePHP or CodeIgniter, even if that means that for the new features some code will be written that already exists (eg.: maybe utility functions) in the old code.
is it possible to integrate one of these frameworks into an existing app?
which one is easier?
do you have any links on how to do it?
thanks.
I have very little experience with CakePHP so my answer is going to be about CodeIgniter. I played with CakePHP for about a day and that was almost two years ago. In my opinion it will probably be easier to integrate with CodeIgniter although someone more experienced with CakePHP might prove me wrong.
Here is the approach I would take. I have never done this, but it seems like a logical way to approach the problem. I suppose this approach would also work with CakePHP.
First, start with a fresh CodeIgniter install using the latest version.
Next, create controllers and actions (controller methods) that mirror the current structure of the application. For example, if you had a page with the URL http://example.com/users/view you would create a Users controller with a view() method.
Next, create view files for each of the current files of the application and load them via the appropriate controller methods. The goal here is to get the application working using CodeIgniter's routing system although at this point you won't be utilizing any models, libraries, or helpers.
Once you have the application sitting on top of CodeIgniter, start refactoring it to fit into the MVC pattern. Pull out application logic (queries, form handling, etc...) from the view files and place them into the controllers. Keep all presentation logic and HTML in the views.
Next, refactor the controllers. This is where it gets tricky because controller code can be placed into models, libraries, or other controller methods. A good starting point would be to take all of the queries and put them into appropriate models. Compare your controllers and see if there is any code duplication. That is a good sign that you should remove it from the controller and place it elsewhere. Unfortunately I can't really tell you where because it differs in each situation.
Continue refactoring your application until you have it in a workable state that you are pleased with...
Hopefully this helps. I certainly missed some critical steps such as setting up and configuring CodeIgniter but if you're serious about doing this I would highly recommend reading through the CodeIgniter User Guide to get a good idea about how it works. You should also get familiar with MVC (model-view-controller) if you aren't already.
There's not really a one size fits all solution here but hopefully I've given you some ideas or at least a starting point to jump off of. If you have any questions or are a little confused drop a comment below and I'll get back to you.
In my opinion, it's easier just to write your controllers in CodeIgniter (I've never used CakePHP) and models, than you just copy paste with some adjustments the views.
I am thinking to create my own simple MVC framework in PHP. I thought it would be good idea to improve my skill in PHP.
I have a questions about admin section, how do you create it?
In kohana, controllers can be in sub-folders:
for example: /controller/admin/admin.php
What is other way? As long code can be shared to parent helpers/libs or parent models.
First thing you have to notice is that Kohana is a HMVC framework. It is a bit different beast, compared to the rest of bunch. In this case admin is not so much a module as it is a namespace (though kohana is still using the PEAR-like "namespacing") for controllers and other classes.
This way additionally lets separate out other parts of application .. lets say you have a lot of code dealing with tagging and tag clouds. Then you can create another namespace/module just for that. And use them as sub-controllers. That's one of HMVC perks.
One other way of separating admin section from general application would be to treat them as separate applications, but then you need another location for shared components (most likely from model layer). Then you have more then one /appliation/ folder on your server.
Or you can do combination of two.
I am assuming here that the reason you want to create yet another MVC framework is indeed to improve your PHP skills, and not to try to create a framework to use in a daily basis at your company, for example. I know that you didn't ask for such advice, but there are so many great MVC frameworks out there (and you probably know many of them already). I think it is a great approach to learn design patterns and increment your skills in PHP (or any other language), though.
As of your question, the most common approaches I have seen is to use different directories, like the "admin" subdirectory you mentioned, for then enforce name suffixes or prefixes for the controllers, like "UsersAdminController.php" e.g, adding "AdminController" at the end.
One thing that using a subdirectory may be better is that it enforces a better separation of concerns, and reduces the possibility of you ending with a lot of classes with simmilar in the same directory, which may cause confusion at some point.
I think creating your own framework is a great idea, if only as an exercise to better understand the structure behind a web app.
I'm doing it so myself, and I think your approach depends very much on how far you want to go.
I started with a multilanguage support subsystem and user database management classes and now I'm moving to content management and database query sanitization.
I keep my classes separated in files and grouped by subsystems in folders, like multilang or admin, I think it's the best approach.
I was wondering if there is a way to make the following process more automated (so links automatically update throughout if the links get changed).
I have a PHP site, with a front controller.
Now I'm wondering how would I go about displaying certain links (to pages) within the different PHP files? (I don't want to actually do so manually...as that would mean if the page name got changed I'd have to manually flick through all the files).
Basically what I'm looking for is a way I can include links to pages on my site easily and automatically.
I had an idea of storing them in an config array and then using some sort of wrapper/helper function in the PHP files to retrieve them from the config array and display them (but not sure if its the best way forward or if there are other ways)?
Perhaps something like how WordPress does it (although I'm not familiar with it I've heard that its using a similar technique...) as what I have is a front controller alongside a mapping array (containing the urls of the pages) - if that helps.
Appreciate all approaches and responses.
I recommend looking at some of PHP's great MVC frameworks for the best examples of using the strengths of MVC to do dynamic routing and access those routes in your views, so they update automatically.
Code Igniter, CakePHP, Zend Framework
I'm partial to CodeIgniter myself, but they all have their strengths.
I seriously suggest you look into adopting one of these frameworks if your application is complex enough to need this level of route management. No need to reinvent the wheel. Using a framework lets you spend less time messing with the nuts and bolts and more time just building your application.
Whether you use the framework or not, they are probably better examples of good object oriented design than you are likely to find in wordpress.