zoukankan      html  css  js  c++  java
  • thinkPHP 模板操作

    1.assign赋值

    $this->assign('title','模板操作');
    $this->assign('bests',$bests);//$bests是二维数组

    2.变量的输出

    Html代码中输出标题如下:

    <title>{$title}</title>

    注意:TP的模板标签和smarty稍有不同

    TP在控制结构/循环/if/else,<>
    而最具体的输出变量 用{$标签}

    3.if/else标签

    /*    //if
        public function ve(){
            $a = mt_rand(3,6);
            $this->assign('ff',$a);
            $this->display();
        }
    */
    /*
        //三元运算符
        public function ve(){
            $a = mt_rand(3,6);
            $this->assign('ff',1);
            $this->display();
        }
    // */
        //数组
        public function ve(){
            $a = array(
                array('id'=>1,'title'=>'中国123'),    
                array('id'=>2,'title'=>'中国456'),    
                array('id'=>3,'title'=>'中国789'),    
            );
    
            $this->assign('ff',$a);
            $this->display();
        }

    在home/view/index目录下创建ve.html

    <include  file = "Public/head"/>
     <body>
    <!--
      <h1>
      
         {$ff?'hello world':00000}<br/>
    
    //if的操作 <if condition = "$ff eq 5"> {$ff} <else/>{$ff}000 </if> </h1> -->
    //数组的遍历 <foreach name='ff' item="v"> {$v.title}<br/> </foreach> </body> </html>

     

    4.import导入css,js文件

    在home/view/Index/ve.html

    <head>
    <!--
    <import type="css" file="a.demo" />
    <import type="js" file="cs" />
    -->
    
    <load href = "__PUBLIC__/cs.js" />
     </head> 
    <body>
    <!--
      <h1>
      
         {$ff?'hello world':00000}<br/>
    
        <if condition = "$ff eq 5">
            {$ff}
            <else/>{$ff}000
        </if>
    
    
      </h1>
    -->
        <foreach name='ff' item="v">
            {$v.title}<br/>
        </foreach>
     </body>

    新建一个Public文件夹

    Public里面放入需要引入的文件

    5.load导入css,js文件

    在home/view下建一个public文件夹

    里面是需要引入的头文件

    在Home/view/index目录下引入public文件目录下的模块

     

    代码如下

    ve.html


    <
    include file = "Public/head"/> <body> </body> </html>

    head.html

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <title>Document</title>
    <!--
    <import type="css" file="a.demo" />
    <import type="js" file="cs" />
    -->
    
    <load href = "__PUBLIC__/cs.js" />
     </head>
    
     <body>
    
     </body>
    </html>

    效果图

    6.不要让模板做太多的工作!

     功能:输出数据,而非处理数据
    应该由控制器来处理

  • 相关阅读:
    解决Xcode升级7.0后,部分.a静态库在iOS9.0的模拟器上,link失败的问题
    2014年工作总结
    工作还是事业
    海豚社区阶段性开发总结
    Xcode开发和调试总结
    iOS证书深究
    何为分类,UIImageView举例
    UIWebView的探索
    SugarSync网盘之NSDateFormatter
    ASP.NET程序从IIS6移植到IIS7时出现500.22错误(转)
  • 原文地址:https://www.cnblogs.com/healy/p/6803804.html
Copyright © 2011-2022 走看看