将数据传回CakePHP中的表单

时间:2012-12-16 15:10:35

标签: php cakephp

我的控制器中有2个动作。第一个显示相关HABTM模型的表单字段的表单和获取列表的操作。第二个执行搜索和显示结果的操作。

第一步:

public function advancedSearch() {
    $this->set($this->Restaurant->fetchRelatedData());    
}

此外,我有查看此操作的视图,其中显示以下表单: advancedSearch.ctp

echo $this->Form->create(null, array(
        'type' => 'get',
        'url' => '/restaurants/search', 'inputDefaults' => array(
        'label' => false,
        'div' => false
)));

echo $this->Form->input('companyname', array('label' => 'Name:'));
echo $this->Form->input('addr', array('label' => 'Address:'));
echo $this->Form->input('district_id', array('label' => 'District:'));
echo $this->Form->input('Station', array('label' => 'Subway station(s):'));
// etc.

echo $this->Form->end('Go!');

如您所见,此表单将数据发送到我执行实际搜索的第二个操作。 我需要提一下,我在搜索操作中使用了分页组件,因此我使用了GET方法。

我的问题是用户可能会选择一些“简单”字段和一些多选字段,发送表单,之后他可能想要优化搜索结果。 因此,我需要实现将数据传递回表单的功能,并使用用户之前选择的值填充字段。 我怎样才能做到这一点?感谢。

0 个答案:

没有答案