开发者

codeigniter display warning error if argument in URL not provided

If I don't provide the value in the URL for Codeigniter, it'll display a PHP Error was encountered saying it's missing argument for a function call. I do NOT want it displayed at all. If there's no argument in the URL, it should just reroute to its index function. How do I prevent that from happening?

For example, www.example.com/profile/id/45

anyone w开发者_运维问答ould guess and enter like this "www.example.com/profile/id"

that would generate the error. How do I prevent that? I tried, "if (!isset($id))" but it generated error before it reached to that condition.


just learned that the solution is simple:

function id($id=NULL)
{
 if ($id===NULL)
 {
  redirect....
 }

}


you can also use:

$this->uri->segment(2); // gets 'id'
$this->uri->segment(3); // gets '45'

then do a redirect, check out:

http://codeigniter.com/user_guide/helpers/url_helper.html


use default values for your function

function id($id=0){
   if(there any record with $id being provided){
        //do something
}else{
       //id not provided,set to default values 0 and then
   show_404();
 }

}

no way there could be id = 0 so its automatically showerror without redirect, if user enter the url www.example.com/profile/id ,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜