A single Portal refers to a website (application) where all requests point to a script file, for example, http: \ localhostindex in CI. php, all accesses to the application must go through this portal. it is just a single inspector that enables the implementation of the mvc mode, because the CI framework MVC
About mvc
Here, I will not explain in detail what the MVC mode is. I will just give a brief introduction. the specific information about mvc can be found on the internet. the mvc mode breaks down a project into three parts in my understanding, model, View, and Controller are the abbreviations and combinations of the three words: MVC. MVC is a common agile software development model. it has been widely used in many fields, especially in the desktop programming field. However, it is difficult to implement MVC in script languages like php, especially a few years ago, it was difficult to see the implementation of mvc in the scripting language. However, with the emergence of many frameworks this year, mvc has been initially implemented in various frameworks, here we will only introduce how codeigniter implements mvc.
About a single portal
A single Portal refers to a website (application) where all requests point to a script file, for example, http: \ localhost \ index in CI. php, all accesses to the application must go through this portal. it is just a single inspector that enables the mvc mode to be implemented, because when you access the index. in php, the application will perform a lot of initialization work, call a lot of basic class libraries, and according to the index. the parameters after php load the controller, and then load the attempt, model, and other content information.
All ci files must be called by the controller. because the controller is a super class in CI, that is, other classes are attached to it, when accessing the CI application using a single portal, in index. php is followed by the controller name and the method name in the controller. if you have no idea or cannot understand this, you can download its official documentation from the official CI website, then, learn more about how it works.
The CI official documentation is very detailed and easy to understand. Here we describe the basic principles that do not exist in the document.
Start
Maybe we should first explain how the CI Controller works. a Controller in CI is a class written by the user, which inherits from the Controller class of the system, for example, assume that we want to build an index that can be passed through http: \ localhost \ index. in php \ control \ func \ param1 \ param2, what do we need to do? First, we need to create a file contro in the system \ application \ controllers \ folder. php file. This file is the file where the controller class we want to access is located. in this file, create the following content:
Reference content is as follows: 1 class Controller extends Controller { 2 3 function Controller () 4 { 5 parent: Controller (); 6} 7 8 function func ($ param1, $ param2) 9 { 10 $ this-> load-> model ('momemodel', '', TRUE ); 11 $ data ['data1'] = $ this-> MSomemodel-> getvalue (); 12 $ this-> load-> view ('Welcome ', $ data ); 13} 14}
|
This is not a basic component of a controller, but a controller example that contains the model and view,
First, note that the class name of the controller should be capitalized, and then the constructor of the parent class should be called in the class constructor, followed by the func () method, that is, the second part of the parameter after the url. this method has two parameters. the values of these two parameters are the values of the third and fourth parts of the url, that is, the access method of a single portal is actually: http: \ localhost \ index. php \ controller name \ method name \ parameter 1 of the method \ parameter 2 of the method \......
In the controller class, each method represents a page, that is, many similar operations can be put in a controller to unify the operations.
In the above example, the model and view are loaded in other parts of the func () method, and the model is loaded in the msomemodel in the models folder. the MSomemodel class in the PHP file. this class is responsible for the model part of the application, that is, for data exchange, such as database storage.