哪种方式最适合将数据发送到 MVC 模式中的视图?
Which way is the best for sending data into View in MVC pattern?
我需要将两个用户之间的关系状态(可以具有 'friends'、'undefined'、'ignore' 等值)从模型发送到视图。
在模板中,我需要为每个案例创建一个链接和标签,例如:
switch ($status) {
case 'friends': 'label' = 'Unfriend', 'link' = 'user_controller/unfriend/'.$id;
case 'undefined': 'label' = 'Add to friends', 'link' = 'user_controller/addfriend/'.$id;
...
}
那么我应该在哪里做这个切换 - 在模型中,然后 return 带有标签和链接的数组,或者只是 return 一个字符串并在视图中制作东西。哪种方式更好?
是的,我会选择 模型层 并将视图保留为模板(因为使用 MVP,受 MVC 启发)。引用 great article:
In proper MVC adaptation, the M contains all the domain business logic and the Model Layer is mostly made from three types of - Domain Objects (business logic), Data Mappers (storage) and Services (the bridge communication between other parts)
我需要将两个用户之间的关系状态(可以具有 'friends'、'undefined'、'ignore' 等值)从模型发送到视图。
在模板中,我需要为每个案例创建一个链接和标签,例如:
switch ($status) {
case 'friends': 'label' = 'Unfriend', 'link' = 'user_controller/unfriend/'.$id;
case 'undefined': 'label' = 'Add to friends', 'link' = 'user_controller/addfriend/'.$id;
...
}
那么我应该在哪里做这个切换 - 在模型中,然后 return 带有标签和链接的数组,或者只是 return 一个字符串并在视图中制作东西。哪种方式更好?
是的,我会选择 模型层 并将视图保留为模板(因为使用 MVP,受 MVC 启发)。引用 great article:
In proper MVC adaptation, the M contains all the domain business logic and the Model Layer is mostly made from three types of - Domain Objects (business logic), Data Mappers (storage) and Services (the bridge communication between other parts)