记录视图,用于在模板中创建条件语句



>我在控制器中有一个方法,它将基于 if 语句加载三个不同的视图,如下所示

if(one) {
    $T->L->V('oneview')
}  
if(two) {
    $T->L->V('twoview')
}  
if(three) {
    $T->L->V('threeview')
}  

在所有视图中,我设置了一个类似的模板。假设此模板为这三个不同的视图命名为"菜单导出器"。

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

   <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>
  }

提前谢谢。

我想你能做的最好的方法是,将控制器的链接作为下面的代码发送到你的视图

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>

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

最新更新