开发者

Codeigniter: Is this suitable use of a view as opposed to a controller?

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 v开发者_运维技巧ariable ($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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜