After the user has entered into the action inside the controller, the second step the controller takes is to process any information stored in any necessary models. Unlike the controller, the model exists to help the developer decouple business logic from the< application. Domain logic, or logic and rules that are specific to the application, will reside inside the model. In most cases, the model consists of scripts that connect to a database and processes any number of create, read, update, delete (CRUD) commands. Nothing besides business logic resides here to consider the script a model and loosely coupled with the other components of the MVC pattern.
Let’s look at another example of what might be inside one of the models. If you created an application that required the user to fill out a form and submit, as shown in Figure, the application will initialize the submitted data inside the action, but will save the information to a database inside a model.
This expands on the previous figure, in which you took a look at how the user’s event triggers the appropriate action in a controller. In the following figure, after the user has successfully submitted the form information for signup, the example is expanded by introducing the model into the controller’s action.
In this example, the model will receive all the user’s information sent in by the controller and save it into a database. If there are no errors, the model will return some type of value back to the controller to inform it that the data is processed. After that happens, the user is sent a message that all the data has been successfully processed.
The model allows you to decouple the business logic from both the controller and the view. Decoupling the process from the controller by placing it inside the model will allow the developer to use the code in not only this particular application but also in a new application. Using PHP, you’ll create a simple model for saving account information that is reusable and can be called from the controller.
The model you just created is a crude implementation that uses the mysqli to connect to a database, cleans the data passed into the function, and then saves the data into the database. To incorporate the model into the controller, let’s update the AccountController successAction().
Listing Updates to the AccountController’s successAction()//Action #1 - Sign up for an account form.
The first few lines in successAction() retrieve any data the user has submitted as a POST. This example assumes that the form has three fields: a username, a password, and an e-mail address. After the data is fetched, you initialize the SaveAccount model and save the three fields by calling saveAccount().
Zend Related Interview Questions
|CSS3 Interview Questions||HTML Interview Questions|
|PHP Interview Questions||MySQL Interview Questions|
|Linux Interview Questions||Drupal Interview Questions|
|Magento Interview Questions||MVC Framework Interview Questions|
|CSS Interview Questions||WordPress Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
Getting Started With Zend Framework
Writing Controllers Using Zend_controller
Views, Forms, Filters, And Validators
Database Communication, Manipulation, And Display
Sending And Receiving E-mail
Web Services And Feeds
Creating A Search Engine Using Zend_search_lucene
Caching With Zend Framework
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.