Cakephp 有条件控制的
我将containable与CakePHP结合使用。我的代码是Cakephp 有条件控制的,cakephp,cakephp-2.0,cakephp-2.1,Cakephp,Cakephp 2.0,Cakephp 2.1,我将containable与CakePHP结合使用。我的代码是 公共功能详细信息($slug=”“){ $this->poter->contain('User.id','User.full_name','Song.id','Song.name','Song.name_hindi','Song.slug'); $result=$this->poter->findBySlug($slug); 如果(!$result){ 抛出新的NotFoundException(uuu('Invalid poter
公共功能详细信息($slug=”“){
$this->poter->contain('User.id','User.full_name','Song.id','Song.name','Song.name_hindi','Song.slug');
$result=$this->poter->findBySlug($slug);
如果(!$result){
抛出新的NotFoundException(uuu('Invalid poter-'.$slug));
}
pr(结果);
模具();
$this->poter->id=$result['poter']['id'];
$this->set('result',$result);
}
像这样。现在我将Song.status作为我与歌曲表的关联。我只想获取那些状态为1的记录。可能吗?我可以只选择带有我的代码的活动记录。使用普通查找
虽然神奇的findBy*方法有时很方便,但最好只将它们用于琐碎的查询——您的查询不再琐碎。而是使用普通的查找调用,例如:
$result = $this->Poet->find('first', array(
'contain' => array(
'User' => array(
'id',
'full_name'
),
'Song' => array(
'id',
'name',
'name_hindi',
'slug',
)
),
'conditions' => array(
'slug' => $slug,
'Song.status' => 1 // <-
)
));
$result=$this->poter->find('first',数组(
'包含'=>数组(
“用户”=>数组(
“id”,
“全名”
),
'宋'=>数组(
“id”,
“姓名”,
“印地语名称”,
“鼻涕虫”,
)
),
“条件”=>数组(
“slug”=>$slug,
'Song.status'=>1//添加更多上下文,显示两个表的模型关联代码。。!
$result = $this->Poet->find('first', array(
'contain' => array(
'User' => array(
'id',
'full_name'
),
'Song' => array(
'id',
'name',
'name_hindi',
'slug',
'Song.status = 1' // <-
)
),
'conditions' => array(
'slug' => $slug
)
));