Codeigniter:根据URI段循环加载不同的视图
我有一个从模型中加载的建筑物列表。这些建筑物在我的视图中循环显示,如下所示:
控制器
public function index() {
$data['buildings'] = $this->Base_Model->getUserBuildings();
$this->load->view('game', $data); }
视图
<?php foreach($buildings as $b): ?>
<div class="building">[...]</div>
<?php endforeach; ?>
每个构建都有一些可能的“操作”,例如“信息”、“价格”、“颜色” ”。默认状态显示“信息”。
我希望能够加载特定建筑物的特定操作。
例如,我有一家工厂和一家药店,默认情况下都显示“信息”选项卡。 如果我单击药店的“价格”选项卡,如何显示工厂的“信息”选项卡和药店的“价格”选项卡?
我的网址如下所示:
默认网址
场地/建筑物
显示药店的价格
网站/建筑物/价格/药店
也许我应该寻找部分视图解决方案,但我真的需要建议或解决方案;)
提前非常感谢您(我也为我的英语不好而道歉)
I have a list of buildings that I load from my model. Those buildings are showed in a loop within my view as so :
Controller
public function index() {
$data['buildings'] = $this->Base_Model->getUserBuildings();
$this->load->view('game', $data); }
View
<?php foreach($buildings as $b): ?>
<div class="building">[...]</div>
<?php endforeach; ?>
Each build has a few "actions" possible such as "info", "price", "color". the default state shows the "info".
I want to be able to load a specific action for a specific building.
For example I have a factory and a drugstore, by default both show the "info" tab.
How to, if I click for the "price" tab of the drugstore, show the "info" tab for the factory AND the "price" tab for the drugstore ?
My URLs looks like these :
default one
site/buildings
show price of the drugstore
site/buildings/price/drugstore
Maybe I should look for a partial view solution but I really need an advise or a solution ;)
Thank you very much in advance (I apologize for my bad English too)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不了解更多有关设置的信息,很难说,但您会希望在 Price() 函数中使用某种条件,
是从数据库获取的信息/价格操作吗?
如果是这样,
但如前所述,在不了解有关系统的更多信息的情况下,很难给出一个像样的答案。
without knowing more about the set up its hard to say, but you'll want some kind of conditional in your price() function
are the info/price actions obtained from the database?
if so something like
but as stated without knowing more about the system it is hard to give a decent answer.
像这样:
然后在您的建筑物控制器中您可以添加以下内容:
Something like this then:
Then in your Buildings controller you could add this: