简体   繁体   中英

Codeigniter Do I need to check if a variable is set in view?

Should I be checking for if a variable is set in the view file ? I mean we are controlling what data is being sent to the view, so ideally it shouldn't be necessary.

And if we check a variable and find that it's not set then what should we do ? Redirect to 404 ? Then again redirecting from view doesn't seem right.

What are the possibilities of a view being loaded without a particular variable ?

I am working in codeigniter.

Logic belongs to controllers . You are passing data also from controllers to views.

The best way is to check in your controller, and if it's not exists, do the redirect then.

Views are just visual representation of your data, no logic belongs to there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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