简体   繁体   English

php codeigniter控制器发布后未执行操作

[英]php codeigniter controller not performing action after post

I have a form that posts a search query to my 'search' controller: 我有一个将搜索查询发布到我的“搜索”控制器的表单:

<div id="search_box">
<?php echo form_open('search'); ?>
<?php echo form_input('searchvalue', 'search...'); ?>
<?php echo form_submit('submit', 'Search!'); ?>
<?php echo form_close(); ?>
</div>

In my search controller I have the following code: 在我的搜索控制器中,我有以下代码:

  public function index()
    {
           $page = 'search';
        $category = 'search';

         if($this->input->post('searchvalue')) {
                  redirect('search/query');
         };


......

}

My problem is that it won't do the redirect. 我的问题是它不会执行重定向。 I have the form helper autoloaded. 我有自动加载的表单助手。 What can I do to solve this mystery. 我该怎么做才能解决这个谜。 Is it a case for the batman? 蝙蝠侠有这种情况吗?

In Codeigniter if you ask for a POST variable from the Input class it will return the value or FALSE if the value is empty (Personal Experience) or not found. 在Codeigniter中,如果您从Input类中请求POST变量,则它将返回该值;如果该值为空(个人经验)或未找到,则将返回FALSE。

So Maybe instead put in a Hidden field with a Dummy value and just check for that on each submit. 因此,也许将其放在具有“虚拟”值的“隐藏”字段中,然后在每次提交时进行检查。 You can then perform validation and redirect. 然后,您可以执行验证和重定向。 This will then work if the search query is provided or not. 然后,无论是否提供搜索查询,这都将起作用。

And the ; ; after you if is not valid PHP. 在您之后, if无效的PHP。

For Example: 例如:

<div id="search_box">
<?php echo form_open('search'); ?>
<?php echo form_hidden('mysearchform', 'true'); ?>
<?php echo form_input('searchvalue', 'search...'); ?>
<?php echo form_submit('submit', 'Search!'); ?>
<?php echo form_close(); ?>
</div>

public function index() {

$page = 'search';
$category = 'search';

if($this->input->post('mysearchform') != FALSE) {

    // Remember to Validate your Query

    redirect('search/query');
}

}

Hope I understood that correctly. 希望我理解正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM