我应该在视图、控制器或模型中将文本加粗吗? (Codeigniter,不是不具体的)
让我们参考 '
我有 3 个anchor() 函数来生成 3 个链接。当选择“排序依据”选项之一时,我想删除超链接/锚点()并将其加粗以显示它已被选中,就像上面的页面一样。
现在我正在考虑对 $arr 执行 uri_to_assoc() ,因为所选选项将位于像controller/function/sort_by/best_reviews/..这样的url中,然后基于键(best_reviews)或元素(sort_by) ,在视图中使用以下代码
<?php
$arr = uri_to_assoc(3);
if($arr['sort_by'] == 'best_reviews') {
echo "<strong>Best Reviews</strong>";
} else {
anchor('controller/function/sort_by/best_reviews', 'Best Reviews');
]
?>
现在我相信MVC的想法是在视图中保留少量的php代码(逻辑代码?)。在这种情况下,您是否会将上述代码放入视图中,或者将该逻辑放在控制器/模型中,然后传递最终代码以在数组中显示(echo 或anchor()),然后仅在视图中回显数组? 。
。
小问题(PHP)
如果在 url 中不存在 /sort_by/variable 的情况下未定义 $arr['sort_by'],则语句 if($arr['sort_by'] = = 'best_reviews') 将给出错误。您会将上述所有代码嵌套在 if(isset($arr['sort_by'])){} 中吗?
Lets refer to 'Sort by' section on Yelp:
I have 3 anchor() functions that generate the 3 links. When one of the 'sort by' option is selected, I want to remove the hyperlink/anchor() and bold it to show that it is selected just like on the page above.
Right now I am thinking of doing a uri_to_assoc() to $arr because the selected option will be in the url like controller/function/sort_by/best_reviews/.., then based on what is the key (best_reviews) or element (sort_by), use the following code in view
<?php
$arr = uri_to_assoc(3);
if($arr['sort_by'] == 'best_reviews') {
echo "<strong>Best Reviews</strong>";
} else {
anchor('controller/function/sort_by/best_reviews', 'Best Reviews');
]
?>
Now I believe the MVC idea is to keep little php code (logic code?) in the view. In this case, will you put the above code in the view, or have that logic in controller/model then pass the final code to display (either the echo or the anchor()) in an array and just echo the array in view?
.
.
Mini Question (PHP)
If $arr['sort_by'] is not defined in the case that /sort_by/variable does not exist in the url, the statement if($arr['sort_by'] == 'best_reviews') will give an error. Will u nest all the above code in a if(isset($arr['sort_by'])){} ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在修改演示文稿,因此必须在视图中进行。它与任何业务逻辑无关。您可以在视图中使用代码,但仅用于演示目的;代码的数量没有限制,只限制其用途。
You are modifying presentation, so you must do it in the view. It has nothing to do with any business logic whatsoever. You can use code in the view, but for the sole purpose of presentation; there's no limit on the amount of code, only on the purpose of it.