如何在php中的表单的动作中发送输入数据?

时间:2013-05-07 10:19:36

标签: php html cakephp-2.0

这是我的表格页。

 <?php echo $this->Form->create('Searchs', array('type' => 'get', 'action' => 'view', 'class' => 'navbar-search'));?>

   <input name="q" type="text" class="search-query" placeholder="Search...">

<?php echo $this->Form->end();?>  

<?php echo $this->Form->create('Searchs', array('type' => 'get', 'action' => 'view', 'class' => 'navbar-search'));?> <input name="q" type="text" class="search-query" placeholder="Search..."> <?php echo $this->Form->end();?>

以下是我在控制器中的动作功能

public function view($exam_id = 0, $q = null) {

    $res = array();
    $this->loadModel('Question');        
    $params = array('conditions' => array(
                                       'MATCH(Question.body) AGAINST("'. $q .'")',
                                       'Question.exam_id' => $exam_id,
                                       ));

    if($exam_id && $q){
        $res = $this->Question->find('all', $params);
    }
    $this->set('res',$res);
}

无论在输入“q”中输入什么,我都需要在url中传递它,以便调用视图操作。我该怎么做?

2 个答案:

答案 0 :(得分:0)

您只是在寻找

$q = $_REQUEST['q'];

$q = $_GET['q'];

因为你知道它是一个get参数。

答案 1 :(得分:0)

我发现了,我在寻找什么。这个陈述在我看来需要什么。

`$this->request->data['q'];`