how can get the $new1 value from the given code
$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()')));
Try below code..
$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);
Hope this helps..
If i understand right the select fail if you have no $new1 defined try define default value before 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()')));
By your comment if your question is how you will get same controller value for replace another value,You can try this format of code
$this->request->data['Profile']['Person_type'];
Now if you want to replace it by another value you can try like
$this->request->data['Profile']['Person_type']=1;
Here whatever you give in your field in person_type it will save 1.
Now if you want to replace this value by another model field you can try like
$this->request->data['Profile']['Person_type']=$this->request->data['AnotherModel']['Another_field'];