:::

7-1 讓前後台統一主樣板

  1. 將原本的 admin.tpl 的主要結構另存為 templates/op_create.tpl 
    <h3>管理界面</h3>
    <div class="row">
      <div class="col-md-9">
        <!-- 編輯表單 -->
        {include file="admin_create.tpl"}
      </div>
      <div class="col-md-3">
        <!-- 側邊欄 -->
        {include file="index_side.tpl"}
      </div>
    </div>
    

     

  2. 最後 admin.tpl 看起來像這樣,和 index.tpl 幾乎一模一樣,只差 web_title 不同而已:
    <!doctype html>
    <html lang="en">
    {include file="index_head.tpl" web_title="校園日誌管理"}
    
    <body>
      <header>
        <!-- 導覽列 -->
        {include file="index_nav.tpl"}
      </header>
      <main>
        <div class="container">
          {include file="op_{$op}.tpl"}
        </div>
      </main>
      <footer>
        <!-- Bootstrap JavaScript Libraries -->
        <script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script>
          Fancybox.bind("[data-fancybox]");
        </script>
      </footer>
    </body>
    
    </html>

     

  3. 我們可以讓 admin.php 改套用 index.tpl,只要多設一個 $web_title 變數,並送至樣板即可。
    <?php
    require_once 'header.php';
    
    // 變數過濾
    $op = isset($_REQUEST['op']) ? htmlspecialchars($_REQUEST['op']) : 'create';
    
    switch ($op) {
        case 'store':
            $id = store();
            //執行後轉向
            header("location: index.php?op=show&id=$id");
            exit;
    
        default:
            $op = 'create';
            break;
    }
    
    $smarty->assign('op', $op);
    $smarty->assign('categories', $categories);
    $smarty->assign('year_count', year_count());
    $smarty->assign('web_title', '校園日誌管理界面');
    $smarty->display('index.tpl');

     

  4. index.php 也一樣多設一個 $web_title 變數,並送至樣板即可。
    $smarty->assign('op', $op);
    $smarty->assign('categories', $categories);
    $smarty->assign('year_count', year_count());
    $smarty->assign('web_title', '校園日誌');
    $smarty->display('index.tpl');

     

  5. index.tpl 本身則不再需要設定 $web_title 變數,admin.tpl 也可以刪除了。
    <!doctype html>
    <html lang="en">
    {include file="index_head.tpl"}
    
    <body>
      <header>
        <!-- 導覽列 -->
        {include file="index_nav.tpl"}
      </header>
      <main>
        <div class="container">
          {include file="op_{$op}.tpl"}
        </div>
      </main>
      <footer>
        <!-- Bootstrap JavaScript Libraries -->
        <script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script>
          Fancybox.bind("[data-fancybox]");
        </script>
      </footer>
    </body>
    
    </html>

     

  6. 這樣前後台就可以都用同一個樣板囉!可以試試是否能正常發布文章~
     

:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D52%26tbdsn%3D1848

計數器

今天: 2863286328632863
昨天: 4745474547454745
總計: 7712824771282477128247712824771282477128247712824