doujiejujixi27244 2017-08-02 11:21
浏览 31
已采纳

如果控制器方法中缺少参数,如何重定向?

Suppose I am creating a dynamic file and I will pass variable inside method_name($variable) and $variable having name ("abc") then our path look like for example:

http://localhost/folder_name/index.php/controller_name/method_name/abc

If I remove abc from the following path then url will look like http://localhost/folder_name/index.php/controller_name/method_name/

and then we run on browser then it will show error i.e.

Message: Missing argument 1 for method_name::controller_name().

So, My question is how to redirect a file if variable value is remove from method. I want to redirect a file to controller if method having nothing inside it.

Thank You

  • 写回答

1条回答 默认 最新

  • doujianzhi3358 2017-08-02 11:24
    关注

    Just Check argument

    <?php
    class Blog extends CI_Controller {
    
        public function index($abc = NULL)
        {
             if($abc){
                // IF argument 
                echo 'Hello World!';
             }else{
                // Redirect here if not argument parsed
             }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器