Barebone Framework

Imagine a framework as a website construction kit:

  • Controller: This is the 'manager', receiving requests and directing tasks. It decides which view to display and how.
  • Action: Each action is a specific job within the project, like building the main page or a blog post. For example,
  • Model: Model, representing the data and business logic of the application.,
  • View: This is the content that gets displayed to the user. It's like the individual building blocks such as text, images, and forms.
  • Layout: This is the architectural blueprint of the website. It defines the overall structure and style, including where different elements go and how they look. Think of it as a theme that sets the foundation for the entire website.

Here's the construction process:

  1. Setting the Foundation:

    • The controller first chooses a predefined layout for the page, similar to picking a theme for the website.
      • this->layout->set_layout('default'); sets the default layout (theme) for the views in this controller.
    • This theme includes not just the layout, but also stylesheets (defining the visual appearance) and JavaScript files (adding interactive elements).
  2. Defining the Tasks:

    • When a user requests a specific page, the controller activates the corresponding action.
      • For example, indexAction is the action responsible for the homepage, while another action might build a contact form page.
  3. Gathering Materials:

    • The action gathers all the necessary data to display the content, akin to collecting the specific building materials needed for that page.
  4. Building the Content:

    • The gathered information is then used to render the specific view needed for that page, similar to constructing the actual content blocks.
  5. Assembling the Page:

    • The rendered view, containing the specific content, is then integrated into the chosen layout (theme).
      • Imagine putting the finished building blocks into their designated spaces within the overall website structure defined by the theme.
  6. Presenting the Masterpiece:

    • Finally, the completed page, combining layout, view, styles, and scripts, is sent to the user's browser for them to see.

MVC is a software architecture that allows for the separation of business logic from the user interface. In this architecture, the user sees and interacts with the view that, in the case of Web applications, is generated HTML code (along with JavaScript, CSS, images, etc.)

MVC

User actions are passed (as HTTP requests, GET or POST methods) to the controller. The controller is a piece of code that handles and processes user input and then reads and makes necessary changes to the model, which is responsible for the storage and modification of data. (In simple terms, the model consists of the database structure and contents, and the code used to access it.) Then, the controller generates the proper view that will be sent and displayed to user.