CI Framework Learning Notes (i)-environment installation, basic terminology and framework processes, CI learning 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, refers to the framework of the portal file index.php. The front controller itself is a design mode, 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:ci Framework System files, 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:
Let Nginx support. htaccess (This article does not mention the use of. htaccess rewritten content, which you can refer to) http://www.php100.com/html/program/nginx/2013/0905/5537. Htmlci Framework integrated Smarty, accustomed to use Smarty template engine for children's shoes can see http://www.kankanews.com/ICkengine/archives/70302.shtml configuration 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:
Index.php is a front-end controller that initializes all the resources required by the framework, loads the application base configuration, receives requests from all users, and routes user requests through the route if the cache file exists, it bypasses the usual order of execution and is sent directly to the client. Security data filtering. This is before the application controller is loaded. The application controller loads the database driver, class library, business logic class, and possibly other resources, processing the user's request view to send to the client. If the cache is turned on, the view is cached for subsequent requests.
Beginner Help PHP Program CI Framework Development come on, take a look.
The general method is the UL nesting, that is, the main menu Ul-li embedded in the child menu UL, to use the two-level cycle
First cycle the main menu, to have a fixed condition to determine the main menu, such as the main menu uid==0 or other ...
- Column name </li>
if ($news _item[' uid '] = = 0) {//Judge and get the main menu
echo "
- ". $news _item[' title ']. '
';
foreach ($news as $child _item)://Cycle two times
if ($news _item[' id ') = = $child _item[' uid ']) {//Judge and get the corresponding sub-menu
echo "
- "." SS ". $child _item[' title ']." </li> ";
}
Endforeach;
echo "</ul></li>";
}
Endforeach;?>
</ul>
Of course, this is limited to level two menus, multilevel or infinite poles, you can use function recursion
Function menu ($uid =0) {//Set default starting from main Menu
Global $news;
foreach ($news as $news _item):
if ($news _item[' uid ') = = $uid) {
echo "
- ". $news _item[' title ']. '
';
Menu ($news _item[' id '); Recursive invocation
echo "</ul></li>";
}
Endforeach;
}
------Call Method------------------------------
>
Who has the CI framework of the Chinese manual send me a chant
zend framework to spend a lot of time, not suitable for fast learning,
now domestic and foreign framework procedures are very much, such as SPEEDPHP,QEEPHP,CAKEPHP,TP, etc.
according to the landlord's requirements, then only CI , personally feel good,
about CodeIgniter
CodeIgniter is a set of application development frameworks and toolkits for developers of PHP Web sites. She offers a rich set of standard libraries and simple interfaces and logical structures to enable developers to develop projects faster. Using CodeIgniter can reduce the amount of code written and devote your energies to the creative development of your project. The
CodeIgniter was developed by Ceorickellis of Ellislab Corporation. Its core framework is specifically written for this program, while many other class libraries, auxiliary functions, and subsystems come from the Content management system ExpressionEngine written by Rickellis and Paulburdick. Inspired by rubyonrails we created a PHP framework and introduced the concept of a framework into the general consciousness of the web community.
She is a small but powerful PHP framework, and as a simple and "elegant" toolkit, she can build a fully functional WEB application for PHP programmers. If you are a developer who has trouble sharing a host and worrying about deadlines for a customer, if you're tired of those silly, clumsy frameworks, then CodeIgniter is what you need if ...
* You want a small frame.
* You need great performance.
* You need a wide range of compatible PHP versions and configurations (e.g. PHP4) on standard hosts.
* You want a framework that is almost only 0 configured.
* You want a framework that doesn't need to use the command line.
* You want a framework that doesn't need to stick to restrictive coding rules.
* You are not interested in PEAR this large-scale integrated class library.
* You don't want to be forced to learn a template language (although you can choose the template parser you require).
* You don't like complexity, love simplicity.
* You need clear, complete documentation.
The most important is that the CI document is simple and easy to understand, haha
want to learn, you can go to CI China to see, you don't need me to put your address it
http://www.bkjia.com/PHPjc/900542.html www.bkjia.com true http://www.bkjia.com/PHPjc/900542.html techarticle CI Framework Learning Notes (i)-environment installation, basic terminology and framework processes, CI learning notes when the first use of the CI framework, it is intended to write a CI source reading notes series, unfortunately ...
-