(i) Introduction
This article mainly describes the cake architecture, and how to install the configuration using this architecture to get started to develop.
(b) requirements (1) to understand the basic PHP code. (2) A apache+mysql+php development environment has been configured.
(iii) Body (1) Cake Introduction
Cake is an MVC framework based on PHP, free and open source. It is simpler than some other PHP architectures, such as the Zend Framework, to enable faster and more flexible creation of network applications. So it's easy for beginners to get started.
Cake has the following characteristics:
Have a friendly and active community
A flexible MIT License
Compatible PHP4 and PHP5
Database interaction using CRUD
Application Scaffolding
Code generation automatically (code generator)
MVC Architecture
Clear, clean, highly customizable URLs and routing request distributors
Built-in validation verification
Quick and flexible template mechanism (PHP syntax, with helpers)
Ajax, JavaScript, HTML forms and more View assistant tools
Messages, cookies, security, sessions (session), and components that request processing
A flexible ACL access control mechanism
Data cleanup
Flexible View Caching caching
Localization
can work in any subdirectory, with little or no need to change any Apache-related configuration
(2) Configuration development
Download cake from http://cakephp.org/, the current latest version is: 1.2.3.8166
After downloading to the root directory of the server, such as:/wwwroot/first_app, and can change the root directory directly pointing to First_appappwebroot, such as: DocumentRoot "D:phpwwwrootfirst_ Appappwebroot "
Restart the Apache service. Browse: http://localhost/
If you see the same page as this one, your Apache service is configured correctly. You can also see 4 tips on the page, and yellow is what you have to configure.
The configuration is as follows:
1. Find Configure::write in first_appappconfigcore.php (' Security.salt ', ' dyhg93b0qyjfixfs2guvouubwwvnir2g0fgac9mi ');
Just change the Back button to any string of 40 or so.
2. Change file First_Appappconfigdatabase.php.default file name to: database.php, changing the database connection inside, you can delete the configuration of test, 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 needs to be changed to writable.
After you change it, you can browse http://localhost/again, and you'll notice that the yellow tip turns green all over.
4. Routing configuration, this is the key to the entire configuration to ensure that the key to the correct.
The action that the route uses to map URLs and controllers
Default route for URL styles:
Http://example.com/controller/action/param1/param2/param3
Modify httpd.conf Open Mod_rewrite
1 Get rid of #loadmodule Rewrite_module modules/mod_rewrite.so before #
2 at the same time change allowoverride none to allowoverride all
Such as:
Options FollowSymLinks
AllowOverride All
The above is to set all the site directory to allowoverride all, if the All,apache service will. htaccess to control the route, set to none, will not be processed under the directory. Routing in htaccess
You can specify a separate directory for routing, and you need to add the directory you want to specify. such as:
AllowOverride All
You need to restart the Apache service after changing the httpd.conf.
(3) using the architecture
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 Browse: Http://localhost/Items, after the results are as follows: