cakephp总结
参考资料
CakePHP 2.x 菜谱:访问速度比cakePHP官网快很多
立刻渲染view
$this->set('title_for_layout','提示');
$this->set('error', $errMsg);
$this->render('/Elements/ajax');
$this->response->send();
$this->_stop();
调试
在 controller 中设置debug级别为2
public function beforeFilter(){
parent::beforeFilter();
Configure::write('debug', 2);
}
打印sql语句
debug($this->ModelName->getDataSource()->getLog(false, false)); exit;
#或者
ConnectionManager::getDataSource('default')->getLog(false, false);
#直接输出sql
ConnectionManager::getDataSource('default')->showLog();
#在model里可以这样写
$this->getDataSource()->showLog();
全局常量和方法
pr()
带<pre>
标签的 print_r。 Convenience wrapper for print_r(), with the addition of wrapping <pre> tags around the output.
常用cakephp自带函数
Hash提取二维数组
$users = Array(
Array(
'user'=>Array('id' => 123,'name'=> 'fred','surname' => 'bloggs')
),
Array(
'user'=>Array('id' => 245,'name' => 'fred','surname' => 'smith')
),
Array(
'user'=>Array('id' => 356,'name' => 'joe','surname' => 'smith')
)
);
$ids = Hash::extract($users, '{n}.user.id');
// $ids will be array (123, 245, 356)
$ids = Hash::extract($users, '{n}.user[name=fred].id');
// $ids will be array (123, 245)
$surname = Hash::get($users, '0.user.surname');
// bloggs
注意:{n}后面没有
.
posted on 2020-03-13 11:07 aworkstory 阅读(130) 评论(0) 编辑 收藏 举报