2014-05-21 49 views
0

如何从给定的代码得到$名new1值如何控制在CakePHP中获取值

$heroprofile = $this->Profile->find('all', array('conditions' => array('Profile.Person_name' => $album, 'Profile.Category' => 'Movies'))); 

//$this->set('movies',$this->Moviemaster->find('all',array('conditions' => array($new => $album)))); 
$this->set('heroprofile', $heroprofile); 

foreach ($heroprofile as $value) { 
    $new1 = $value['Profile']['Person_type']; 
    echo $new1; 
} 

$this->set('coll', $this->Moviemusic->find('all', array('fields' => array('DISTINCT(Moviemusic.type)'), 'conditions' => array($new1 => $album), 'limit' => 4, 'order' => 'rand()'))); 
+0

你应该做**的print_r($ heroprofile)** – Girish

+0

你想在这里到底是什么?或者你有任何错误? –

+0

实际上我需要从$ heroprofile获得一个值..并且需要将该值放在另一个查询中查找相同页面 – user3530708

回答

2

试试下面代码..

$heroprofile=$this->Profile->find('all',array('conditions' => array('Profile.Person_name' => $album,'Profile.Category' => 'Movies'))); 
$this->set('heroprofile',$heroprofile); 
$newvalue = array(); 
foreach ($heroprofile as $value) { 
    $new1=$value['Profile']['Person_type']; 
    $newvalue[]= $this->Moviemusic->find('all',array('fields' => array('DISTINCT(Moviemusic.type)'),'conditions'=>array($new1 => $album),'limit'=>4,'order'=>'rand()')); 
} 
$this->set('coll',$newvalue); 

var_dump($newvalue); 

希望这有助于..

0

如果我明白 选择失败,如果你没有定义$ new1 尝试定义之前的默认值FOR

$heroprofile=$this->Profile->find('all',array('conditions' => array('Profile.Person_name' => $album,'Profile.Category' => 'Movies'))); 

       //$this->set('movies',$this->Moviemaster->find('all',array('conditions' => array($new => $album)))); 
       $this->set('heroprofile',$heroprofile); 
$new1 = "some default person type"; 
foreach ($heroprofile as $value) { 
        $new1=$value['Profile']['Person_type']; 
        echo $new1; 
       } 

      $this->set('coll',$this->Moviemusic->find('all',array('fields' => array('DISTINCT(Moviemusic.type)'),'conditions'=>array($new1 => $album),'limit'=>4,'order'=>'rand()'))); 
0

通过你的评论,如果你的问题是你将如何得到相同的控制器值替换另一个值,你可以试试这个代码格式现在

$this->request->data['Profile']['Person_type']; 

,如果你想通过另一种价值,你可以将其替换尝试像

$this->request->data['Profile']['Person_type']=1; 

在这里无论你给你的领域person_type这将节省1

现在,如果你想更换由该值诺特尔模型字段,你可以尝试像

$this->request->data['Profile']['Person_type']=$this->request->data['AnotherModel']['Another_field']; 
相关问题