【发布时间】:2012-06-29 12:45:24
【问题描述】:
您好,我是 cakephp (v.1.3) 的新手。我正在尝试做一些简单的事情。
我有两个表:fichas[id,... etc] 和 labos[id,laboratorio,ficha_id] 所以“labos”属于“fichas”。 (labos.laboratorio 是 ENUM 字段)。
我想查看给定 labos.id 和 labos.laboratorio 的“ficha”,所以我在“home.ctp”中包含了以下代码
<h3>Mostrar Ficha</h3>
<?php echo $this->Form->create('ficha',array('action'=>'localiza'));?>
<?php echo $this->Form->radio('laboratorio',array('A','B','C'),array('A','B','C')); ?>
<?php echo $this->Form->input('id',array('label'=>'Numero','type'=>'text')); ?>
<?php echo $this->Form->end("Mostrar");?>
然后在“fichas_controller.php”中添加以下内容:
function localiza(){
$laboratorio=$this->data['Ficha']['laboratorio'];
$id=$this->data['Ficha']['id'];
if(!$id){
$this->Session->setFlash('Por favor introduzca un valor valido');
$this->redirect(array('action'=>'index'));
}
$this->set('fichas',$this->Ficha->findID($id,$laboratorio));
}
最后在模型“ficha.php”中如下:
function findID($id=null,$laboratorio=null){
return $this->find('all',array('conditions'=>array('Labo.laboratorio'=>$laboratorio,'Labo.id'=>$id)));
}
显然文件views/fichas/localiza.ctp存在
问题是当我按下表单中的提交按钮时,它只会重新加载 home.ctp 页面。看起来控制器的代码没有被执行,因为我试图强制错误消息应该加载索引操作,将 if 条件更改为 true,但结果相同。我已经更改了模型中函数的名称,期望出现错误,但我得到了相同的结果。 我在 home.ctp 页面中有另外两个表单,但调用了另一个操作和模型。 其中一个几乎相同,并且工作正常。 我无法弄清楚错误。
提前感谢您的帮助。 马塞洛。
【问题讨论】:
-
你能发布从 home.ctp 生成的 HTML 吗?
标签: forms cakephp cakephp-1.3