Cake PHP 学习备忘录[一]

2008-04-23 | 11:04 上午分类:Cakephp, VC & PHP | 标签: | 224 views

你的数据库中的表也应该遵循下面的命名规则:

● cake使用的表名(Table name)应该有英文的复数形式组成,比如users, authors, articles. 注意,对应的model是单数形式

● 所有的表 都必须有一个主键叫做 id

● 如果你需要关联tables,使用外键比如 article_id 。表的名字是单数,必须是小写,比如id

● 另外,最好遵从下面的命名规则以便更方便的使用某些功能

Include a ‘created’ 列

Include a ‘modified’列

UltraEdit 32 中高亮显示 CakePHP 的 视图(View),.ctp ,同理可扩展其它自定义后缀:

找到 UltraEdit 32 的 安装目录,打开 wordfile.txt 找到 253 行,在后面添加上 CTP 就行了。

例如:/L3″HTML” HTML_LANG Nocase Noquote Block Comment On = <!– Block Comment Off = –> File Extensions = HTM HTML SHTML HTT HTA HTX CFM JSP PHP PHTML ASP CTP

在CakePHP 中使用自定义全局变量,常量,全局函数等全局性东西:(/app/config/bootstrap.php),另一个办法是在 app 目录重载 app_controller.php,这样可以让全局函数。

Bootstrapping CakePHP

If you have any additional configuration needs, use CakePHP’s bootstrap file, found in /app/config/bootstrap.php. This file is executed just after CakePHP’s core bootstrapping.

This file is ideal for a number of common bootstrapping tasks:

  1. •Defining convenience functions
  2. •Registering global constants
  3. •Defining additional model, view, and controller paths

数据库乱码

app\config\database.php中设置 ‘encoding’ => ‘utf8′;

更新单个表项或多个表项时要指明 id ,如果不指明则是插入新行

$this -> Controller -> id = $this -> Session -> read('id');

$this -> :Controller -> id = $this -> Session -> read(’id’);

$this -> :Controller -> saveField(’actived’,'Y’)

saveField() 和 save()

上面也是说在 CakePHP 中如何使用 Update 这样的效果

显示乱码:

可以修改 view 文件夹下的 模版文件,添加:

$html -> charset(”UTF-8″);

Session使用:

Controller :$this->Session->write($key,$value); $this->Session->read()…..

使用数组:$dataArray1 = array (’g'=>$generalfile,’b'=>$bigfile,’s’=>$smallfile,’m'=>$minifile);  $this -> Session -> write($dataArray1);

View:$session->read($key);…..

function afterSave()
{
// mail me when a new bookmark is added
mail(’example@example.com’, ‘Bookmark saved to database’);
return true;

}
不使用 layout: $this-> layout = false;
Model 名和数据库名不对应:var $useTable = 'Table Name';
==============

setFlash
string $flashMessage
string $layout = ‘default’
array $params
string $key = ‘flash’
将变量$flashMessage中的信息写入Session(提供给之后的flash()方法来获取)。
如果$layout设置为“default”,该消息被存储为’<div class=”message”> ‘.$flashMessage.’</div> ‘.如果$default设置为”,该消息就按原样保存。如果参数为其他任何值,该消息以 $layout 所指定的格式保存在Cake view里.

新增 我收集、整理的一些 CakePHP 学习资料:这里下载 [2008.5.6]

17fav 收藏本文

授权方式:署名,非商业用途,保持一致,转载时请务必以超链接(白板博客)的形式标明文章原始出处和作者信息及本声明。欢迎订阅本博客
  1. 2条评论 关于 “Cake PHP 学习备忘录[一]”

  2. 高辉 发表于2008-05-06

    您写的关于cakephp的东东,对我很有帮助.我刚刚开始学习cakephp,可不可以发给我点关于cakephp的学习资料呢?谢谢!^_^
    希望能跟您学到更多的有用的…..

    天天快乐!
    Good Luck!

  3. DYH1919 发表于2008-05-06

    CakePHP 的资料的确很少,中文就更少了,我也初学,推荐要使用的资源:官方的 API,Manual,有问题的话可以上 CakePHP 的 Google Group 询问。另外我的收藏里有很多很好的 CakePHP 相关文章:http://www.oblank.com/favorites

发表您的评论

您的名字: (*必填)

您的邮箱: (*不会被公布 ,必填)

您的网站: