【问题标题】:Php codeigniter:Passing empty arguments through redirectPHP codeigniter:通过重定向传递空参数
【发布时间】:2016-05-25 05:28:58
【问题描述】:

这是我的控制器功能

Class Customer Extends CI_controller{

 public function view($page='customer-new-bill',$param=null,$type='normal')
  {

  }
}

有时我不希望 $param 参数有一个值,所以我只是在重定向中使用这种方式清空第二个参数

redirect('customer/view/customer-view-invoice//invoice');

但是没有用。

我想通过重定向传递空参数可以吗?

注意:

我使用这种方法$this->view('','','invoice') 它有效,但我需要一个redirect

【问题讨论】:

  • 尝试使用 $param=0 默认 0 作为空整数,如果您将其传递为 null,则您的第三个参数将变为第二个
  • 简单解决方法

标签: php codeigniter redirect


【解决方案1】:

如果要发送空参数,则在最后发送

Class Customer Extends CI_controller{

   public function view($page='customer-new-bill',$type='normal', $param=null)
   {

   }
 }

并使用这条路线

$route['customer/view/(.*)'] = "customer/view/$1/$2";

路线(.*) 工作范围不受限制。

【讨论】:

    【解决方案2】:

    最好有 defaultnull parameters 在末尾​​p>

    Class Customer Extends CI_controller{
    
       public function view($page='customer-new-bill',$type='normal', $param=null)
       {
    
       }
     }
    

    所以现在重定向

    redirect('customer/view/customer-view-invoice/invoice/');

    您也可以根据需要创建路线

    $route['customer/view/(:any)/(:any)'] = "customer/view/$1/$2";
    $route['customer/view/(:any)/(:any)/(:any)'] = "customer/view/$1/$2/$3";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-17
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-08
      • 2017-04-15
      • 2015-05-19
      相关资源
      最近更新 更多