Cakephp如何在使用一个字段搜索时显示特定记录

时间:2014-08-20 07:00:44

标签: cakephp cakephp-1.3 cakephp-2.3

我是cakephp的新手。

我有两个彼此相关的表(student和payment_detail)。 学生有很多付款详情 付款详细信息属于学生。

我有一个搜索视图:

<?php echo $this->Form->input('Student.roll_no', array('label' => __('Roll No'))); ?> 
<?php echo $this->Form->end(__('View')); ?> 

控制器中的查看方法:

public function view(){ 
        if ($this->request->is('post')) { 
            $this->request->data; 
            return $this->redirect(array('action' => 'detailedview'));                   
        }
}

当我点击查看按钮时,它会将我重定向到详细视图。所以我的问题是如何为控制器创建详细视图方法,以检索与特定roll_no相关的记录中的所有字段。

1 个答案:

答案 0 :(得分:0)

您需要:

1)将您的视图功能更改为:

public function view( $id=null ){ 
        if ($this->request->is('post')) { 
            $this->redirect(array('action' => 'detailedview', $id));
        }
}

2)在控制器中添加以下功能:

public function detailedview( $id=null ) {
....
}

在您这样做之前,我建议您再次阅读文档并进行博客教程。