CakePHP 编程笔记

1. Notice (8) : Undefined variable: layout

原因可能是component的命名不符合规范:JigoCity对应的文件名应该jigo_city.php

如果这个没错,而你的app_controller里面包含了acl组件,那么可能是plugin目录下缺失ACL的实现

2. 进入localhost:8000/admin时未要求登录验证,直接进入了后台页面

原因是app_controller.php中有如下语句:

function beforeFilter() {
$this->Auth->allow('*');
}

去掉才可以进入CakePHP默认的验证界面(auth组件)

3. CakePHP程序调用堆栈:

v1.5 [PHP Web Page]
PHP Application
http://localhost:8000//index.php (suspended at line breakpoint )
beforeFilter(): /jigocity_v1_5/app/controllers/app_controller.php at line 84
beforeFilter(): /jigocity_v1_5/app/controllers/app_controller.php at line 83
startupProcess(): /jigocity_v1_5/cake/libs/controller/controller.php at line 526
startupProcess(): /jigocity_v1_5/cake/libs/controller/controller.php at line 524
_invoke(): /jigocity_v1_5/cake/dispatcher.php at line 187
_invoke(): /jigocity_v1_5/cake/dispatcher.php at line 185
dispatch(): /jigocity_v1_5/cake/dispatcher.php at line 171
dispatch(): /jigocity_v1_5/cake/dispatcher.php at line 97
/jigocity_v1_5/index.php at line 83
http://localhost:8000//index.php

4. 登陆后未显示用户名密码错误,但是页面未正常跳转

可能是你设置了如下语句:

$this->Auth->autoRedirect = false;

uncomment it if so.

5. security component 加载后, 会在form表单提交时添加token隐性参数以防止跨站脚本攻击和表单伪造。但是也会导致未授权表单提交动作返回404页面链接不存在的错误。

6. 更改datetime格式:

http://www.mikebernat.com/blog/CakePHP_-_Changing_the_Default_Value_of_a_Date-Time_Input

7. 设置默认的按列排序

$tableHeaders = $html->tableHeaders(array(
$paginator->sort('id'),
__('Role', true),
$paginator->sort('username'),
$paginator->sort('firstname'),
$paginator->sort('email'),
__('Actions', true),
));

8. 关联保存

<div id="deal-main">
<?php
echo $form->input('Deal.slug', array('class' => 'slug'));
echo $form->input('Deal.min_buyers');
echo $form->input('Deal.max_buyers');
?>
</div>
<div id="deal-details">
<?php
echo $form->input('DealDetail.0.lang_id',array('label'=>__('Language', true)));
echo $form->input('DealDetail.0.currency_id');
echo $form->input('DealDetail.0.title');
echo $form->input('DealDetail.0.subject');
echo $form->input('DealDetail.0.brief');
echo $form->input('DealDetail.0.description');
?>
</div>

9. tinymce usage:

*) put it under plugin directory

*) change tinymce_hook.php:

/**
* Actions
*
* Format: ControllerName/action_name => settings
*
* @var array
*/
public $actions = array(
'Deals/admin_add' => array(
'elements' => 'DealDetail0Description',
),
'Deals/admin_edit' => array(
'elements' => 'DealDetail0Description',
),
);

10. cakephp的命名规范

比如读取外键关联的表数据时,如果失败,则需要检查外键名称,表名称,字段名称是否符合命名规范。

例如: 外键为lang_id, 那么这在视图是个下拉列表选择框。

view中应该是:

echo $form->input('DealDetail.0.lang_id',array('label'=>__('Language', true)));

controller中:

$langs = $this->Language->find('list', array(
'fields' => array('name_en')
));

model中:

var $belongsTo = array(
'Language' => array(
'className' => 'Language',
'foreignKey' => 'lang_id'
),

)

你可能感兴趣的:(编程,PHP,脚本,tinymce,cakephp)