Codeigniter:相对于控制器来说,这是否适合使用视图?
我有一个带有索引函数的控制器,它可以采用三个参数
function index($name,$date1,$date2){
在控制器中,我有 if 语句,如果设置了 $date1,则设置一个变量 ($data['one']),如果设置了 $date2,则设置一个变量($data['two'])。
然后 $data 被传递到我的视图(“结果”),其中根据设置/未设置的内容进行各种级别的处理。
我应该在控制器中进行处理,然后根据设置/未设置的内容调用多个视图还是无关紧要?
谢谢
I have a controller with an index function which can take three parameters
function index($name,$date1,$date2){
Within the controller i have if statements such that if $date1 is set, set a variable ($data['one']), and if $date2 is set, set a variable ($data['two']).
$data is then passed to my view ('result') where there is various levels of processing depending on what is/is not set.
Should i rather have the processing within my controller, and then call multiple views depending on what is/is not set or does it not matter?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您创建了多个视图。如果有任何重复,那就是错误的。始终牢记 DRY(不要重复自己)原则,这样就不会出错。一般来说,每个控制器不需要多个视图。另外,当你说处理时,我想知道这是什么意思。所有逻辑都应该放在控制器中,而您的视图应该保留用于简单的 if 语句,以禁止输出由于控制器中的逻辑被认为是不必要的东西,或者可能是 foreach 循环数组并打印其内容。
Let's say you created multiple views. If there is any duplication whatsoever - it's wrong. Always keep the DRY - Don't Repeat Yourself - principle in mind and you can't go wrong. Generally you shouldn't need more than one view per controller. Also, when you say processing, I wonder what that means. All logic should go in the controller, while your views should be reserved for simple if statements to prohibit things from being outputted that due to the logic in the controller is not deemed neccessary, or perhaps a foreach to loop through an array and print its content.