溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

thinkPHP控制器變量在模板中如何顯示

發(fā)布時(shí)間:2021-07-14 09:20:56 來源:億速云 閱讀:131 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹了thinkPHP控制器變量在模板中如何顯示,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

具體如下:

控制器中變量

public function register() {
  $type = I("param.type");//1.學(xué)生注冊(cè) 2.教師注冊(cè) 3.其他注冊(cè)
  $this -> assign("type", $type);
    //q全部部門
  $depart1 = M("Depart") -> where("status=1 and fid=0") -> order("id asc") -> select();
  $this -> assign("depart1", $depart1);
  $this -> display();
}

模板中引用位置一:php代碼中,直接用$i;

<php>
  echo $i;
</php

模板中引用位置二:模板中直接應(yīng)用{$i}或者 class="{$unlogined}"

<font color="red">注意:1.非相關(guān)人員,嚴(yán)禁注冊(cè)。{$i}</font><br>
<php>
  $logined = is_array($_SESSION['userInfo']) ? "" : "hide-div";
  $unlogined = $logined == "hide-div" ? "" : "hide-div";
</php>
<div id="unlogined-div" class="{$unlogined}">

模板中引用位置三:模板標(biāo)簽中用,如condition中用,不加{}。

<if condition="$type neq 4">
  <div class="form-group">
    <label for="" class="control-label col-sm-3">一級(jí)部門: <span class="text-danger">*</span></label>
    <div class="col-sm-9">
      <select name="depart1_id" id="depart1_id" onchange="depart1change()" class="form-control input-sm">
        <option value="-1">-----請(qǐng)選擇一級(jí)部門-----</option>
        <foreach name="depart1" item="vo">
          <option value="{$vo.id}">{$vo.name}</option>
        </foreach>
      </select>
    </div>
  </div>
  <div class="form-group">
    <label for="" class="control-label col-sm-3">二級(jí)部門: <span class="text-danger">*</span></label>
    <div class="col-sm-9">
      <select name="depart2_id" id="depart2_id" onchange="depart2change()" class="form-control input-sm">
        <option selected='selected'>-----請(qǐng)先選擇一級(jí)部門-----</option>
      </select>
    </div>
  </div>
  <div class="form-group">
    <label for="" class="control-label col-sm-3">三級(jí)部門: <span class="text-danger">*</span></label>
    <div class="col-sm-9">
      <select name="depart3_id" id="depart3_id" class="form-control input-sm">
        <option selected='selected'>-----請(qǐng)先選擇二級(jí)部門-----</option>
      </select>
    </div>
  </div>
</if>

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“thinkPHP控制器變量在模板中如何顯示”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI