记录视图以在模板中创建条件语句

时间:2015-04-16 04:34:04

标签: php codeigniter

我在控制器中有一个方法,它将根据if语句加载三个不同的视图,比如

if(one) {
    $T->L->V('oneview')
}  

if(two) {
    $T->L->V('twoview')
}  

if(three) {
    $T->L->V('threeview')
}  

在所有视图中,我设置了一个类似的模板。假设这个模板名为" menu-exporter"对于这三种不同的观点。

在此菜单导出器模板中,有一个按钮可以执行某些操作。

   <button> A Link that will generate the button </button>

我现在想要实现的是,如何记录视图以在模板中创建条件语句,以便我可以在此模板中创建与此按钮不同的链接?

喜欢这个:

  if($view == 'oneview') {
   <button> The link go to the school </button>
  }

  if($view == 'twoview') {
   <button> The link go to the office  </button>
  }

  if($view == 'threeview') {
   <button> The link go to the home</button>
  }

提前致谢。

1 个答案:

答案 0 :(得分:1)

我想你可以做的最好的方法是,从你的控制器发送链接到你的视图,如下面的代码

if(one) {
    $data['my_link'] = "link1";
    $T->L->V('oneview')
}  

if(two) {
    $data['my_link'] = "link2";
    $T->L->V('twoview')
}  

if(three) {
    $data['my_link'] = "link3";
    $T->L->V('threeview')
}  

并使用my_link变量生成按钮链接或href为

<button> <?php echo $my_link;?> </button>

这样,您可以在控制器中保持视图干净和业务逻辑。

相关问题