CI Framework Source Reading Notes 1,CI Framework source notes
The first use of the CI framework, it is intended to write a CI source reading notes series, unfortunately, has not acted. There are few recent projects and there is some time to write something. So prepare to write down some notes and experience before, on the one hand to make a memo, on the other hand always remind yourself: learn and learning to have a way out, forget the past means betrayal!
Basic Terminology Description
Before the beginning of this article, it is necessary to make a simple explanation of the recurring terms in the text, if you are familiar with this part, you can skip it altogether. The recurring and mentioned terms in this article include:
Front-end controllers (Front Controller):
A component that centrally controls all requests for a user, sending a user's request to a specific application controller. In the CI framework, it refers to the CodeIgniter class. The front-end controller itself is a design pattern, detailed reference to the "Java EE design mode".
Application Controller
An application controller is a specific controller that handles a user request URL, typically placing a set of related processing or requests in an application controller, for example: Usercontroller may contain user registration, authentication, personal information, personal page, and other related actions.
Mvc
The cliché of a term that is a code layering and organization pattern. The code is divided into m (Model, business logic), V (view, views), C (Controller, director) and other layers, so as to facilitate the separation of the business logic part and the view rendering portion, reducing the coupling of the code. Currently, many frameworks in PHP are based on MVC patterns, such as ZF,YII,CI, etc.
Route Routing
Although named route, this is not a router, but rather a process of intercepting a user's request and forwarding the request to a specific controller processing. Different frameworks have different routes, but the fundamentals are the same.
Hook Hooks
The initial hook refers to "a link in messaging that monitors the delivery of messages and adds specific processing before the message is processed." The hook here is to add or change the core functionality of the system without changing the core source of the framework, most typically by running a specific script before the controller loads or after the load is complete.
CI Framework Configuration
The basic environment of this article: Linux x86_64 gnu/linux. PHP (CGI) +nginx+mysql+redis installed (so many of the server-related configurations in this article are Nginx-based and temporarily ignore Apache servers).
First download the CI Framework source code, the download address is: Http://codeigniter.org.cn/downloads The current stable version is 2.2.0. Extract the source code to the folder (assuming the /usr/nginx/html/ci directory).
Before configuring the CI framework, first browse through the framework's directory structure:
which
application : The directory of the application, all of your application code should be located in this directory
index.php : Portal file for Frames
Static : We set up the directory, put some css,image and JS and other static files (this can be placed in the application directory, to see a person's preferences)
System: The CI framework is also the main part of the source reading
user_guide : User Guide, similar to the offline user manual.
The CI framework needs to be configured in a relatively small number of places:
1. Configure Routes
The default application controller and 404 pages are configured in routes.php. Open the application/config/routes.php file with the following configuration:
$route [' default_controller '] = "index"; $route [' 404_override '] = ';
2. Configuring the Database database.php
If your application needs to provide dynamic content, then the database is almost an essential configuration. Open a application/config/database.php file with the following contents:
The CI framework supports multi-data flow connections, and default is the currently defaulted connection, and Active_record is used to specify whether arm (active Record Model) is enabled. Each configuration item is very concise and there are no more introductions.
3. Remove index.php
Now to access your application, the URL should look similar to this:
Test.xq.com/index.php/indextest.xq.com/index.php/welcome
Note that each request will have a index.php segment. Removing index.php will make the URI more aesthetically pleasing.
Open the test.xq.com.conf file you just added and add the following configuration to the server:
if ($request _filename!~*/(favicon.ico|static|uploads|js|javascript|css|images|robots\.txt|index\.php|index\ . html) { rewrite ^/(. *) $/index.php?$1 last;}
Once the server is restarted, the URL is now accessed in the following way:
Test.xq.com/indextest.xq.com/welcome
Is it more concise:D
4. Add the. html access suffix
There may also be people who prefer to add a specific suffix to the URL, such as the. html suffix to make your application more like a series of static files. The configuration method is, in application/config/config.php , change the following configuration to:
$config [' url_suffix '] = '. html ';
For more configuration of the CI framework, refer to:
Configure Vhost
In order to facilitate access (compared to the way IP address access, domain access has better memory), we can configure Vhost, configured as follows: Into the Nginx vhost directory, Create a new profile (in this article, test.xq.com.conf, in general, each of our vhost will be named after the domain name). Enter the following in the configuration file:
server { listen ; server_name test.xq.com; Root /usr/nginx/html/ci/; access_log logs/xq_access_log main; Error_log logs/testsq.log error; CharSet GBK; Index index.php; Location ~. *\. ( PHP|PHP5)? $ { include fastcgi_params; Fastcgi_param script_filename $document _root$fastcgi_script_name; Fastcgi_pass 127.0.0.1:9000; }}
There are no other rewrite configurations in the server at the moment, and later, when configuring the CI framework, we can add more configuration classes that support CI friendly URLs.
Open the local host file and add an entry in host:
10.130.130.130 test.xq.com
where 10.130.130.130 should be the IP address of your server.
The CI framework can now be accessed through the domain name in the browser.
Framework Process
Before concluding this article, let's take a look at the basic process of the CI framework, which will always be read through the source code, so it is necessary to study it carefully. Refer to the flowchart on the CI Framework user manual:
The basic execution process is as follows:
The next step begins with the CI source reading tour.
Who can explain this PHP code in the CI framework
This is a method within a class.
The function is: The browser uses the POST request sends the SHOP_ID to the server, this shop_id is the manufacture_id in the database, according to this shop_id query database, the record which is found in JSON format string output to the browser
Problems encountered in the PHP CI framework
Tip Fatal Error:class ' Test_model ' not found in D:\wamp\www\CodeIgniter_2.1.2\system\core\Loader.php on line 303
The meaning of this Test_model class cannot be found
Your class name is wrong, of course you can't find it.
The following is the model code with the file name test_model.php: (the class name should be consistent with the file name)
Class Test_m extends ci_model{//preferably uppercase are capitalized to be changed to Test_model
The following is the Contraller code, the file name is user.php
$this->load->model (' Test_model '); It doesn't get a class test_model when it loads.
It should be successful.
http://www.bkjia.com/PHPjc/899962.html www.bkjia.com true http://www.bkjia.com/PHPjc/899962.html techarticle CI Framework Source Reading Notes 1,CI Framework source notes the first use of the CI framework, it is intended to write a CI source reading notes series, unfortunately, has not acted. Recently ...