Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
检查布局中的用户身份验证并在用户登录时在布局中输出不同的元素是否是不好的做法?
我通常在视图中看到这一点,而不是在布局中。
我尝试将用户身份验证值传递给正在做我想做的布局,但如果这是不好的做法,我不想这样做。
您的代码应该始终与您的视图/布局分开,例如设置用户是否登录等。检测和输出是另一回事。大多数模板引擎,例如 twig 或 smarty,都有 if 语句和逻辑运算符来检查值是什么。在布局中包含不同的元素没什么大不了的。这实际上是观点的一部分,不是吗?对我来说似乎是正常的做法
tldr:继续。你听起来不错。