mysql – Cakephp从另一个视图中检索id
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql – Cakephp从另一个视图中检索id,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3577字,纯文字阅读大概需要6分钟。
内容图文
![mysql – Cakephp从另一个视图中检索id](/upload/InfoBanner/zyjiaocheng/906/e8b6e7858bb4436795f5541206c5b55e.jpg)
尝试创建一个表单和一个确认页面,要求确认用户是否想要与用户建立关系.表单只有一个字段,该字段带有一个id并将用户引导到确认页面.确认页面有两个按钮,当用户点击确认表单将被提交给数据库时确认和拒绝,如果用户点击拒绝,表单中的数据将被丢弃.确认页面还将打印他们尝试添加的用户的用户名.
我似乎无法从添加页面(add_admin.ctp)中检索id.
如何从原始添加页面(add_admin.ctp)访问id以在确认页面(confirm.ctp)中使用它?
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'));
?>
解决方法:
将ID添加到重定向:
$this->redirect(array('controller' => 'Relationships', 'action' => 'confirm'));
成为像:
$this->redirect(array('controller' => 'Relationships', 'action' => 'confirm', $this->request->data['Relationship']['receiver_id']));
内容总结
以上是互联网集市为您收集整理的mysql – Cakephp从另一个视图中检索id全部内容,希望文章能够帮你解决mysql – Cakephp从另一个视图中检索id所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。