When it comes to building websites with various forms of content, the road often leads to 3 choices;
- Pure PHP/mySQL
- PHP Framework
- Content Management System
Although each method would have its own strengths and weaknesses, the PHP framework is a great place to build, build and build. Since each controller will actually be the name of each web page, it makes it nice and convenient to build reusable pages which are easy to find and edit. For example, you build a contact form with specific validation. Then, you reuse it later but the client wants different validation and fields. The changes would be very simple to change update and even transfer to another Codeigniter installation.
Furthermore, it uses the MVC approach to display web pages.
How does MVC work? The (C) is the controller and is the workhorse.
If a database is used, the controller does a short call to the model.
To get the code from the model into the controller,
Then, the controller sends data to the view. Now, the view returns data back to the controller that sends the desired data to the browser.
If a framework like Codeigniter is used, the model can be bypassed and the database can be accessed from the controller. However, using models just to access a database or xml file, controllers to load and organize the page to the brower and the view for HTML/CSS makes it simple to separate php, database access and style.
To access the database,
$query = $this->db->query(‘SELECT, UPDATE query goes here’);
With a framework like Codeigniter, there is not too many limitationss since a controller can call a view file which accesses a database, makes a database queries and contains html source code. In this case, using a view is almost like using pure php; except the controller is the page name.