Codeigniter我是否需要检查变量是否在视图中设置?

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.