$ this-> params在cakephp模型中返回null [英] $this->params returns null in cakephp model
问题描述
我决定在一些模型beforeSave中添加一些关于控制器和操作的额外数据,如下所示:
model
public function beforeSave(){
$ this-> data [$ this-> alias] ['path'] ='blah blan';
debug($ this-> params);
die(); //用于调试!
}
调试的打印输出返回 null !我使用的模型是评论插件的注释模型。我需要访问params来获取当前的控制器,操作和一些url参数。
的确,我打算改变评论插件列出评论的方式
最后我找到了解决方案:它在 Router
对象方法 getParams()
;
//在模型中
public function beforeSave(){
$ this-> data [$ this-> alias] ['path'] ='blah blan';
debug(Router :: getParams());
die(); //用于调试!
}
它会打印出以下内容:
array(
'plugin'=> null,
'controller'=>'qurans',
'action' >'view',
'named'=> array(
'comment'=>'0'
),
'pass'=& b $ b(int)0 =>'8'
)
)
I decided to add some extra data about the controllers and actions in some model beforeSave as follows:
//in the model
public function beforeSave() {
$this->data[$this->alias]['path'] = 'blah blan';
debug($this->params);
die(); //for debugging!
}
The printout of debug returns null! The model I uses is the Comment model of the comments plugin. I need to access params to get the current controller, actions and some url parameters.
Indeed, I plan to change the way that comments plugin lists the comments from model based to be path based to solve the issue of need comments for more than one action depend on the same model.
Finally I found the solution: It is in Router
object method getParams()
;
//in the model
public function beforeSave() {
$this->data[$this->alias]['path'] = 'blah blan';
debug(Router::getParams());
die(); //for debugging!
}
it prints out something like:
array(
'plugin' => null,
'controller' => 'qurans',
'action' => 'view',
'named' => array(
'comment' => '0'
),
'pass' => array(
(int) 0 => '8'
)
)
这篇关于$ this-> params在cakephp模型中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!