Section 1

Database Configuration

Your app/config/database.php file is where your database configuration all takes place. A fresh install doesn't have a database.php, so you'll need to make a copy of database.php.default. Once you've made a copy and renamed it you'll see the following:

在app目录下,必须依存一个db配置文件,路径是 /app/config/database.php 这个文件安装cake之后是不存在的,你可以从database.php.default拷贝一份出来,下面来看看文件里有什么: 

app/config/database.php

var $default = array('driver'   => 'mysql',
                     'connect'  => 'mysql_connect',
                     'host'     => 'localhost',
                     'login'    => 'user',
                     'password' => 'password',
                     'database' => 'project_name',
                     'prefix'   => '');

Replace the information provided by default with the database connection information for your application.

One note about the prefix key: the string you enter there will be prepended to any SQL call that Cake makes to your database when working with tables. You define it here once so you don't have to specify it in other places. It also allows you to follow Cake's table naming conventions if you're on a host that only gives you a single database. Note: for HABTM join tables, you only add the prefix once: prefix_apples_bananas, not prefix_apples_prefix_bananas.

你的的应用的连接信息替换掉默认的信息就可以了。需要注意一点:表名前缀一旦定义它就会在全局数据库使用时生效,你不能在其他地方制定它了。它允许你在单一数据库状况下使用表名公约。注意对于join表的时候,你加了前缀,表明一定是: 前缀+表名 而不是 前缀+表名1+前缀+表名2.

CakePHP supports the following database drivers: cakephp支持如下的数据库驱动:

  1. mysql

  2. postgres

  3. sqlite

  4. pear-drivername (so you might enter pear-mysql, for example)

  5. adodb-drivername

The 'connect' key in the $default connection allows you to specify whether or not the database connection will be treated as persistent or not. Read the comments in the database.php.default file for help on specifying connection types for your database setup.

$default 中的连接允许你指定是否采用持久化连接,请阅读 database.php.default中的帮助信息,查看你使用的数据库连接类型。

Your database tables should also follow the following conventions:
你的数据表应遵守如下的约定:

  1. Table names used by Cake should consist of English words in plural, like "users", "authors" or "articles". Note that corresponding models have singular names.

  2. Your tables must have a primary key named 'id'.

  3. If you plan to relate tables, use foreign keys that look like: 'article_id'. The table name is singular, followed by an underscore, followed by 'id'.

  4. If you include a 'created' and/or 'modified' column in your table, Cake will automatically populate the field when appropriate.

 1 表名必须使用英语复数形式,比如: users authors articles 注意相应的Model名字要用单数形式
 2 你的表必须含有主键"id”(这点和 rails一样,只不过rails 可以通过 set_primary_key 设定 注释)
 3 如果你要使用关系表,表名是单数然后加下划线加id,类似于 article_id(这点也比较死板感觉)
 4 如果你的表里字段名有叫 created或者modified的,cake会自动重名

You'll also notice that there is a $test connection setting included in the database.php file. Fill out this configuration (or add other similarly formatted configurations) and use it in your application by placing something like:

var $useDbConfig = 'test';

你也许注意到默认配置里有个叫test的配置项,你也可以填写一个或者使用你指定名字的配置名,例如:
Inside one of your models. You can add any number of additional connection settings in this manner.
在你的model里你可以增加任意数量的额外链接设置在你的配置里

Section 2

Global Configuration

CakePHP's global configuration can be found in app/config/core.php. While we really dislike configuration files, it just had to be done. There are a few things you can change here, and the notes on each of these settings can be found within the comments of the core.php file.

cake的全局配置可以在/app/config/core.php中找到。虽然我们都不喜欢配置文件,不过这是必须要做的:( 有几件事情,你可以修改这里,不过要注意每个设置项都要在core.php的注释里。
DEBUG: Set this to different values to help you debug your application as you build it. Specifying this setting to a non-zero value will force Cake to print out the results of pr( ) and debug( ) function calls, and stop flash messages from forwarding automatically. Setting it to 2 or higher will result in SQL statements being printed at the bottom of the page.

Also when in debug mode (where DEBUG is set to 1 or higher), Cake will render certain generated error pages, i.e. "Missing Controller," "Missing Action," etc. In production mode, however (where DEBUG is set to 0), Cake renders the "Not Found" page, which can be overridden in app/views/errors/error404.thtml.

DEBUG设成成不同的值,可以帮助你调试你的应用程序,这个选项必须设置值的。cake通过调用pr和debug函数来打印信息,自动停止刷新消息如果自动forward。设置它为2或者更高,会导致,sql语句被打印在页面底部。 同样,在调试模式里,cake会回显某个生成的错误页面如: 没有控制器 没有Action 等等。在产品模式下,你最好把DEBUG设成0 cake会回显 not found 页面 你可以覆盖掉 /app/views/errors/error404.thtml改变显示的错误页面
CAKE_SESSION_COOKIE: Change this value to the name of the cookie you'd like to use for user sessions in your Cake app.
CAKE_SESSION_COOKIE:COOKIE的session名字

CAKE_SECURITY: Change this value to indicate your preferred level of sessions checking. Cake will timeout sessions, generate new session ids, and delete old session files based on the settings you provide here. The possible values are:
 session的有效期时间设定。如果超时,cake就会生成性的id并商处旧的session文件。本参数可以设定的值:

  1. high: sessions time out after 20 minutes of inactivity, and session id's are regenerated on each request 高: session有 20分钟不活动

  2. medium: sessions time out after 200 minutes of inactivity 中 超过200分钟

  3. low: sessions time out after 600 minutes of inactivity 低 超过600分钟

CAKE_SESSION_SAVE: Specify how you'd like session data saved. Possible values are: 指定 session存在哪里,可以设定的值:

  1. cake: Session data is saved in tmp/ inside your Cake installation

  2. php: Session data saved as defined in php.ini

  3. database: Session data saved to database connection defined by the 'default' key.

 1 cake 报错在/tmp 你安装cake的地方
 2 php 根据php。ini的设置
 3 数据库,session会被报错在默认连接池的数据库中

Routes Configuration

"Routing" is a pared-down pure-PHP mod_rewrite-alike that can map URLs to controller/action/params and back. It was added to Cake to make pretty URLs more configurable and to divorce us from the mod_rewrite requirement. Using mod_rewrite, however, will make your address bar look much more tidy.

Routes are individual rules that map matching URLs to specific controllers and actions. Routes are configured in the app/config/routes.php file. They are set-up like this:
routing类似于精简的modrewrite模块,用于映射url成 /controller/action.params。 routing设置使得cake通过mod_rewirte生成漂亮的url,使用它使得你的url更整洁。
routes的个人设置规则可以使得符合的url被影射到指定的控制器和动作,routes被设置在app/config/routes.php中

Route Pattern

<?php
$Route->connect (
    'URL',
    array('controller'=>'controllername',
    'action'=>'actionname', 'firstparam')
);
?>

Route Pattern

<?php
$Route->connect (
    'URL',
    array('controller'=>'controllername',
    'action'=>'actionname', 'firstparam')
);
?>

Where:

  1. URL is the regular expression Cake URL you wish to map,

  2. controllername is the name of the controller you wish to invoke,

  3. actionname is the name of the controller's action you wish to invoke,

  4. and firstparam is the value of the first parameter of the action you've specified.

Any parameters following firstparam will also be passed as parameters to the controller action.

The following example joins all the urls in /blog to the BlogController. The default action will be BlogController::index().

Route Example

<?php
$Route->connect ('/blog/:action/*', array('controller'=>'Blog', 'action'=>'index'));
?>

Route Example

<?php
$Route->connect ('/blog/:action/*', array('controller'=>'Blog', 'action'=>'index'));
?>
A URL like /blog/history/05/june can then be handled like this:

Route Handling in a Controller

<?php
class BlogController extends AppController
{
 function history ($year, $month=null)
 {
   // .. Display appropriate content
 }
}
?>

The 'history' from the URL was matched by :action from the Blog's route. URL elements matched by * are passed to the active controller's handling method as parameters, hence the $year and $month. Called with URL /blog/history/05, history() would only be passed one parameter, 05.

The following example is a default CakePHP route used to set up a route for PagesController::display('home'). Home is a view which can be overridden by creating the file /app/views/pages/home.thtml.

Setting the Default Route

<?php
$Route->connect ('/', array('controller'=>'Pages', 'action'=>'display', 'home'));
?>

Setting the Default Route

<?php
$Route->connect ('/', array('controller'=>'Pages', 'action'=>'display', 'home'));
?>

小资情调 | 评论(2) | 引用(0) | 阅读(1241)
edwardproAdmin Email Homepage
2008/06/10 12:38
set names="utf-8"
学习笔记 Email Homepage
2008/06/09 17:34
正在学cakephp,我现在不知道怎么改数据库的编码啊,我的页面是UTF-8的,数据库也是UTF-8的,但读出来数据都是问号啊~
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]