사용자가 사용자와 관계를 만들지 묻는 확인 페이지와 양식을 만들려고합니다. 양식에는 ID가있는 필드가 있으며 사용자에게 확인 페이지가 표시됩니다. 확인 페이지에는 양식의 데이터가 삭제 될 것이라는 사용자의 클릭을 거부하는 경우 양식이 데이터베이스에 제출 될 것인지 확인하는 확인 및 거부 버튼 두 개가 있습니다. 또한 확인 페이지에는 추가하려는 사용자의 사용자 이름이 인쇄됩니다.다른보기에서 ID를 검색하는 Cakephp
내가 추가 페이지 (add_admin.ctp)에서 ID를 검색하는 것 같습니다.
확인 페이지 (confirm.ctp)에서 사용하려면 원래 추가 페이지 (add_admin.ctp)의 ID에 어떻게 액세스합니까?
public function add_admin() {
$this->set('title_for_layout', 'Send A Relationship Request');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
$account_id=$this->User->find('list', array(
'fields'=>array('account_id'),'conditions' => array(
'id' => $this->Auth->user('id'))));
if ($this->request->is('post')) {
$this->Relationship->save($this->request->data);
if ($this->Relationship->validates(array('fieldList'=>array('receiver_id','Relationship.accountExists'))))
{
$this->Relationship->save($this->request->data);
$this->Session->setFlash('The relationship has been saved');
$this->redirect(array('controller'=>'Relationships', 'action'=>'confirm'));
} else {
$this->Session->setFlash('The relationship could not be saved. Please, try again.');
}
}
$this->set('account_id', $account_id);
}
public function confirm($id){
$this->set('title_for_layout', 'Relationships');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
//$id = $this->request->data(`Relationship.receiver_id`);
//$id = $this->params('Relationship.id');
$id = $this->params['Relationship']['id'];
$compName = $this->request->data(`Account.company_name`);
$findName=$this->Account->find('list', array(
'fields'=>array('company_name'),'conditions' => array(
'id' => $id)));
debug($id);
pr($compName);
pr($findName);
$this->Relationship->unbindModel(array('hasMany'=>array('Invoice')));
if ($this->request->is('get')) {
$this->request->data = $this->Relationship->read(NULL, $id);
}
else
{
if ($this->Relationship->save($this->request->data)) {
//$this->Session->setFlash('You have successfully confirmed the relationship.');
if($this->request->data['submit'] == "type_1")
{
$this->Session->setFlash('The relationship has been confirmed');
$this->redirect(array('controller' => 'fields','action' => 'add'));
}
if($this->request->data['submit'] == "type_2")
{
$this->Session->setFlash('The relationship was denied');
$this->redirect(array('controller' => 'templates','action' => 'index'));
}
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
$this->set('compName', $compName);
$this->set('findName', $findName);
$this->set('id', $id);
}
add_admin.ctp
<?php
echo $this->Form->create('Relationship', array('action'=>'add_admin'));
echo $this->Form->hidden('sender_id',array('label'=>'Enter your eBox ID: ', 'type'=>'text', 'default'=>$account_id));
echo $this->Form->input('receiver_id',array('label'=>'Receiver eBox ID: ', 'type'=>'text'));
echo "<br />";
echo $this->Form->end('Submit');
?>
confirm.ctp
Do you want to create a relationship with <?php echo $findName ?>
<?php
echo $this->Form->create('Relationship', array('action'=>'confirm'));
echo $this->Form->input('id', array('type'=>'hidden'));
echo $this->Form->button('Confirm', array('name' => 'submit', 'value' => 'type_1'));
echo $this->Form->button('Deny', array('name' => 'submit', 'value' => 'type_2'));
?>
감사하지만 여전히 작동하지 않습니다. params를 올바르게 사용하고 있습니까? 아니면 내가 params를 사용하고 있어야합니까? – user1402677
이것은 올바른 방법 중 하나입니다. 'receiver_id'보다는'$ account_id'를 전달하기를 원할지라도 다른 곳에 문제가 있어야합니다. – Ross
왜 로스인가? – user1402677