Home  >  Article  >  Backend Development  >  Getting Started with CakePHP Architecture_PHP Tutorial

Getting Started with CakePHP Architecture_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:21760browse

(1) Introduction

This article mainly introduces the CakePHP architecture and how to install and configure it to get started with development.

(2) Requirements (1) Understand basic PHP code. (2) The development environment of Apache+MySQL+PHP has been configured.

(3) Text (1) Introduction to CakePHP

CakePHP is a free and open source MVC framework based on PHP. It is simpler than some other PHP frameworks (such as zend framework), allowing users to create network applications faster and without losing flexibility. Therefore, it is easy for ordinary beginners to get started.

CakePHP has the following features:

Having 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

Fast and flexible template mechanism (PHP syntax, with helpers)

With AJAX, JavaScript, HTML forms and more view assistant tools

Mail, cookies, security, session, and request processing components

Flexible ACL access control mechanism

Data cleaning

Flexible view 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

After downloading, extract it to the root directory of the server, such as: /wwwRoot/First_App. At the same time, you can change the root directory to point directly to First_AppAppWebRoot, such as: DocumentRoot "D:PHPwwwRootFirst_Appappwebroot"

Restart the Apache service. Browse: http://localhost/

Getting Started with CakePHP Architecture_PHP Tutorial 帮客之家

If you see the same page as this, it means your Apache service is configured correctly. At the same time, you can see 4 prompt messages on the page. The yellow ones are the ones you must configure.

Configuration is as follows:

1. Find Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') in First_AppappconfigCore.php;

Just change the following keys to any string of about 40 characters.

 2. Change the file name of the file First_Appappconfigdatabase.php.default to: database.php, change the database connection inside, and delete the test configuration. 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, you need to change it to writable.

Save the changes and browse http://localhost/ again. You will find that all the yellow tips above turn to green.

Getting Started with CakePHP Architecture_PHP Tutorial

4. Routing configuration, this is the key to the entire configuration and ensures that the following can be done correctly.

Routing is used to map URLs and controller actions

Default route for URL style:

 http://example.com/controller/action/param1/param2/param3

Modify httpd.conf to enable mod_rewrite

1 Remove the # before #LoadModule rewrite_module modules/mod_rewrite.so

 2At the same time, change AllowOverride none to AllowOverride all

For example:

 

 Options FollowSymLinks

AllowOverride all

 

The above is to set all website directories to Allowoverride all. If it is all, the apache service will use .htaccess to control routing. If it is set to none, the routing in .htaccess in the directory will not be processed

You can specify a separate directory for routing, and you need to add the directory to be specified in . Such as:

 

AllowOverride all

 

After changing httpd.conf, you need to restart the Apache service.

 (3) Usage structure

If the configuration is correct, you can add your own code.

 3.1 Create database table

CreateTableItems

 (

id int (11) unsigned auto_increment,

name varchar(200),

text varchar(200),

CreateTime timestamp default current_timeStamp,

primary key (id)

 )

insert into Items(name,text) values('Item1','Item1content');

 3.2 Create Model:First_AppappmodelsItem.php

createItemextendsAppModel{

var $name = 'Item';

 }

 ?>

 3.3 Create Controller:First_AppappcontrollersItems_Controller.php

class ItemsController extends AppController {

var $name = 'Items';

var $scaffold;

 }

 ?>

3.4 Browse: http://localhost/Items, the results are as follows:

Getting Started with CakePHP Architecture_PHP Tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752066.htmlTechArticle (1) Introduction This article mainly introduces the CakePHP architecture and how to install and configure it to get started with development. (2) Requirements (1) Understand basic PHP code. (2) The development environment of Apache+MySQL+PHP has been configured...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn