开发者

Undefined variable: errors from empty 3rd uri params (code igniter)

开发者 https://www.devze.com 2023-03-17 19:20 出处:网络
I have many controllers with functions like function search($person) { if empty($person) { redirect(\'...\');

I have many controllers with functions like

function search($person) {
    if empty($person) {
            redirect('...');
        }
    else {
        .........
    }
}

I wasn't getting 开发者_如何学编程Undefined variable errors before, but now i do (if i go to .../search/) without passing a $person. I found i can fix this by doing function search($person = null) but i was wondering if there is a "better" way. I am also curious why i wasn't getting errors before (on localhost) but am now.. (on godaddy).

THANKS!!!


I wouldn't provide a default value for the argument in this case, function search($person) is how the function should be declared if $person is indeed a required argument. You want this to throw a warning so you can quickly see what's wrong during development.

In production, you simply switch off error reporting/error display.
See http://codeigniter.com/user_guide/general/errors.html.

0

精彩评论

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

关注公众号