Skip to main content

MVC (Model View Controller) : Codeigniter Club



MVC will divide an application into three functional parts:

  • Models — deals with your database, carries out computations, and more. In short, it is where your business logic is located.
  • Views — forms the presentation layer of the application, where the data from your models are embedded.
  • Controllers — used to connect models and views. A controller will route user requests to the appropriate model. After that, once the model has done its job, the controller loads the relevant view.

This architectural pattern also gives developers the flexibility to reuse code for multiple views. For example, you can apply the same navigation bar on every webpage of your application.

Moreover, as both views and models are entirely separate, the front-end developers can work in parallel with the back-end team to speed up the development process.

Note that CodeIgniter also subscribes to Object-Oriented Programming (OOP). As such, models and controllers are PHP classes that extend the base classes provided by the framework.

Views are also called PHP files, but the bulk of their content is HTML/CSS. Only a few snippets of PHP code are present, which are used to display the data from models.

PHP MVC Frameworks simplify working with complex technologies by;

  • Hiding all the complex implementation details.
  • Providing standard methods that we can use to build our applications.
  • Increased developer productivity, this is because the base implementation of activities such as connecting to the database, sanitizing user input etc. are already partially implemented.
  • Adherence to professional coding standards.

Comments

Popular posts from this blog

How to secure codeigniter website?

CSRF Protection (Cross-Site Request Forgery) CSRF process of an attacker tricking their victim into unknowingly submitting a request. CodeIgniter provides CSRF protection out of the box, which will get automatically triggered for every non-GET HTTP request, but also needs you to create your submit forms in a certain way. URI Security CodeIgniter contain following character in URI ·          Alpha-numeric text (Latin characters only) ·          Tilde: ~ ·          Per cent sign: % ·          Period: . ·          Colon: : ·          Underscore: _ ·          Dash: - ·          Space Password Handling ·        ...

Codeigniter installation & setup: Codeigniter Club

                    Windows Environment   Install XAMPP or WAMP   Download and Unzip the package from Codeigniter.com   Extract all the documents in the server space (htdocs or www directory) Linux Environment  Download and Unzip the package from Codeigniter.com  Place the extracted folder in /var/www (in WAMP) or xampp/htdocs (XAMPP) Base URL   Go to application/config/config.php  Define base URL as $config['base_url'] = 'http://localhost/path/to/folder'; How to remove index.php from URL? go to root  create htaccess file  Add below code inside it  RewriteEngine on RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] Note: .htaccess code varies depending on the hosting server. Some hosting servers (e.g.: Godaddy) need to use an extr...