Home Backend Development PHP Tutorial cakephp手册系列1:配置cakephp方法

cakephp手册系列1:配置cakephp方法

Jun 13, 2016 pm 01:11 PM
cakephp controller database security

cakephp手册系列一:配置cakephp方法

前言:使用cakephp开发项目有一年多的时间了,回想刚开始连配置都要按照视频来照搬的场景,感觉进步确实还是不小的,所以现在想将学习和开发过程当中碰到的各种问题总结一下作为一个手册以备将来用到的时候参考,由于水平有限,难免会有些错误和不足,欢迎大家善意的纠错和指正,阿本感激不尽。



? ? 配置cakephp是使用它进行开发的前提条件,我曾经也在这个问题上苦恼许久,因为教程的不足还有我看过的视频的一些疏忽,导致我刚开始配置cakephp就用了好几天的时间,汗一下。其实配置cakephp是非常简单的,主要可以分为以下几个步骤。


1.下载
? ? 现在用于开发的比较稳定的cakephp版本为1.3.12,可以到cakephp的官网进行下载?下载地址:www.cakephp.org
? ? 下载完成后解压,放入你服务器的项目目录中,比如apache的htdocs中,解压后的根目录下应该包括以下几个文件/文件夹

1. app
2. cake
3. vendors
4. .htaccess
5. index.php
6. README
Copy after login

?

?

2.配置app/config/core.php文件
? ? ??修改代码

Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
Copy after login

? ? ? ? ?变成

Configure::write('Security.salt', 'ABDCDEFGHIKLMNOPQRSTUVWXYZ');
Copy after login

? ? ? ? ?之后在

Configure::write('Security.cipherSeed', '76859309657453542496749683645');
Copy after login

? ? ? ? ?后面的一串数字中随意输入几个数据,比如

Configure::write('Security.cipherSeed', '76859309657453asdfsdf6749683645');
Copy after login

? ? ? ? ?以便和本地环境进行匹配。

?

?

3.配置app/config/database.php

? ? ? ?database.php是由database.php.default重命名而来,主要是跟数据库的链接配置,配置信息如下

?

    var $default = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'root',
        'password' => 'root',
        'database' => 'test',
        'encoding'=>'utf8'
    );
Copy after login

? ? ? ? ?其中loginmysql数据库登录名,password为密码,database为默认链接数据库,encoding为编码。

?

?

4.(可选配置)配置app/config/routes.php

? ? ? 如果你想改变默认访问页面(即当你输入localhost后默认访问的页面,那么可以在这里进行修改)

?

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Copy after login

? ? ? ? ?controller设为你想要默认的controlleraction设置为默认action,比如

?

Router::connect('/', array('controller' => 'messages', 'action' => 'upload'));
Copy after login

? ? ? ? ?表示默认访问messages/upload

?

?

5.(可选配置)配置cake/libs/controller/controller.php

? ? ? ? ?cakephp的默认views编辑页面为ctp格式的,这在DM下编辑不方便,所以我都会把默认修改为html或者htm格式,方便前台美工修改。

?

var $ext = '.ctp';
Copy after login

? ? ??修改为

?

var $ext = '.htm';
Copy after login

? ? ? ??其实前三个步骤完成了运行cakephp就没有问题了,后面只是自己的习惯性修改而已,你可以根据自己的习惯和项目具体要求进行修改,我就不赘述了。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

17 ways to solve the kernel_security_check_failure blue screen 17 ways to solve the kernel_security_check_failure blue screen Feb 12, 2024 pm 08:51 PM

Kernelsecuritycheckfailure (kernel check failure) is a relatively common type of stop code. However, no matter what the reason is, the blue screen error causes many users to be very distressed. Let this site carefully introduce 17 types to users. Solution. 17 solutions to kernel_security_check_failure blue screen Method 1: Remove all external devices When any external device you are using is incompatible with your version of Windows, the Kernelsecuritycheckfailure blue screen error may occur. To do this, you need to unplug all external devices before trying to restart your computer.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

How to solve discuz database error How to solve discuz database error Nov 20, 2023 am 10:10 AM

The solutions to discuz database error are: 1. Check the database configuration; 2. Make sure the database server is running; 3. Check the database table status; 4. Back up the data; 5. Clear the cache; 6. Reinstall Discuz; 7. Check the server resources ; 8. Contact Discuz official support. Solving Discuz database errors requires starting from multiple aspects, gradually identifying the cause of the problem, and taking corresponding measures to repair it.

Leak reveals key specs of Intel Arrow Lake-U, -H, -HX and -S Leak reveals key specs of Intel Arrow Lake-U, -H, -HX and -S Jun 15, 2024 pm 09:49 PM

IntelArrowLakeisexpectedtobebasedonthesameprocessorarchitectureasLunarLake,meaningthatIntel'sbrandnewLionCoveperformancecoreswillbecombinedwiththeeconomicalSkymontefficiencycores.WhileLunarLakeisonlyavailableasava

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

See all articles