(a) Introduction
This article focuses on cakephp architecture and how to install the configuration to use this architecture for development.
(ii) requirements (1) understand the basic PHP code. (2) The development environment of apache+mysql+php has been configured.
(iii) text (1) cakephp Introduction
CakePHP is a PHP-based, free and open-source MVC framework. It is simpler than some other PHP architectures, such as the Zend Framework, and allows you to create network applications faster and with less flexibility. So it is easy to get started for ordinary beginners.
CakePHP has the following features:
Have a friendly and active community
Flexible MIT License
Compatible with PHP4 and PHP5
Database interaction uses CRUD
Application Scaffolding
Automatic code generation (code generator)
MVC Architecture
Clear, clean, highly customizable URLs and routing request dispatcher
Built-in validation validation
Fast and flexible template mechanism (PHP syntax, with helpers)
Have Ajax, JavaScript, HTML forms and more view helper tools
Messages, cookies, security, sessions, and components requested for processing
Flexible ACL access control mechanism
Data cleanup
Flexible View Cache Caching
Localization
can work in any subdirectory, with little or no need to change any Apache-related configuration
(2) Configuration development
Download cakephp from http://cakephp.org/, the latest version is: 1.2.3.8166
Download and extract to the root directory of the server, such as:/wwwroot/first_app, while you can change the root directory directly point to First_appappwebroot, such as: DocumentRoot "D:phpwwwrootfirst_ Appappwebroot "
Restart the Apache service. Browse: http://localhost/
If you see the same page as this, your Apache service is configured correctly. You can also see the 4 tips on the page, yellow is what you have to configure.
The configuration is as follows:
1. Find Configure::write in first_appappconfigcore.php (' Security.salt ', ' dyhg93b0qyjfixfs2guvouubwwvnir2g0fgac9mi ');
You can change the following key arbitrarily into 40 or so arbitrary strings.
2. Change the file name of the file First_Appappconfigdatabase.php.default to: database.php, make changes to the database connection inside, delete the test configuration, and the final configuration is as follows:
Class Database_config {
var $default = Array (
' Driver ' = ' mysql ',
' Persistent ' = false,
' Host ' = ' localhost ',
' Login ' = ' root ',
' Password ' = ' 123 ',
' Database ' = ' cake ',
' Prefix ' = ',
);
}
3. If first_appapptmp is not writable, it will be changed to writable.
After the changes are saved, browse http://localhost/again, and you will notice that the yellow hints above are all turned green.
4. Routing configuration, this is the key to ensure that the overall configuration of the following can be done correctly.
Route the action used to map URLs and controllers
Default route for URL styles:
Http://example.com/controller/action/param1/param2/param3
Modify httpd.conf to open mod_rewrite
1 Remove #loadmodule Rewrite_module modules/mod_rewrite.so before the #
2 change allowoverride None to allowoverride all
Such as:
Options FollowSymLinks
AllowOverride All
Above is to set all site directories to allowoverride all, if the All,apache service will be the. htaccess to control the routing, set to none, will not be processed in the directory. htaccess routes
You can specify a separate directory for routing, and you need to join the directory you want to specify. such as:
AllowOverride All
The Apache service needs to be restarted after changing the httpd.conf.
(3) using the schema
If the configuration is correct, you can add your own code.
3.1 Creating a database table
Create Table Items
(
ID int (one) unsigned auto_increment,
Name varchar (200),
Text varchar (200),
Createtime timestamp default Current_timestamp,
Primary KEY (ID)
)
Insert into Items (name,text) VALUES (' Item 1 ', ' Item 1 content ');
3.2 Creating Model:First_AppappmodelsItem.php
Create Item extends appmodel{
var $name = ' Item ';
}
?>
3.3 Creating Controller:First_AppappcontrollersItems_Controller.php
Class Itemscontroller extends appcontroller{
var $name = ' Items ';
var $scaffold;
}
?>
3.4 Views: Http://localhost/Items, after the results are as follows:
http://www.bkjia.com/PHPjc/752066.html www.bkjia.com true http://www.bkjia.com/PHPjc/752066.html techarticle (a) Introduction This article mainly introduces cakephp architecture, and how to install the configuration using this architecture for development. (ii) requirements (1) understand the basic PHP code. (2) The development ring of the configured apache+mysql+php ...