Can I call a Model from a View?

后端 未结 4 1816
再見小時候
再見小時候 2020-11-27 21:13

Rather than use a full-blown PHP MVC, I\'m designing one that will best-fit my uses. I have the basic framework done, and have coded the models and controllers I\'ll need to

4条回答
  •  清酒与你
    2020-11-27 21:40

    You can, but you shouldn't. Except for a few extreme cases (and branching your view based on logged-in status is definitely not an "extreme case"), it's pretty much always A Bad Idea to call model stuff from a view.

    What you probably want to do in your situation is pass the boolean to the view through the controller. That way, if you change something about the User model, the view doesn't have to know, so long as the controller keeps the behavior the same.

提交回复
热议问题