本节课大纲: 一、导入CSS和JS文件 1、css link js scr <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/> <script src='__PUBLIC__/Js/test.js'></script> 2.import <import type='js' file='Js.test' /> //导入Public文件夹下面的Js目录中的test.js文件,import标签可以省略type属性,默认就是js的 <import type='css' file='Css.test' /> //可以更改默认文件夹 设置basepath属性 <import type='js' file='Js.my' basepath='./Other'/> 3.load //方法可以自动检测导入的文件类型 <load href='__PUBLIC__/Js/test.js' /> 二、分支结构 1、if <if condition='$sex eq "男"'> 男人是泥巴做的 <else /> 女人是水做的 </if> <if condition='$age lt 18'> 未成年 <elseif condition='$age eq 18'/> 青春年少 <else /> 成年 </if> > gt < lt == eq <= elt >= egt != neq === heq !== nheq <switch name='number'> <case value='1'>一个和尚挑水吃</case> <case value='2'>两个和尚台水吃</case> <case value='3'>三个和尚没水吃</case> <default/> 这里是默认值 </switch> 三、循环结构 1.for <table border='1' width='500'> <for start='10' end='00' name='j' step='-2' comparison='gt'> <tr><td>{$j}</td><td>abc</td></tr> </for> </table> 2.volist <volist name='list' id='v'> {$v.username}<br/> </volist> 3.foreach <foreach name='list' item='v' key='k'> {$k}-------{$v}<br/> </foreach> 四、特殊标签 五、其他标签使用 //示例: <?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ $n=$_GET['number']; //调用index.html模板文件 //name表示标识 //加载第三方类 import ('ORG.My.test'); //$arr=array('a','b','c'); // $arr[0]=array('id'=>1,'username'=>'aaa'); // $arr[1]=array('id'=>2,'username'=>'bbb'); //$arr=array('k1'=>'scan1','k2'=>'scan2'); //$obj=new test; $this->assign('list',$arr); $this->display(); } } <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>--> <!--<script src='__PUBLIC__/Js/test.js'></script>--> <!--<import type='css' File='Css.test'/> <import type='js' File='Js.test'/>--> <title>Document</title> </head> <body> <table border='1' width='500'> <for start='10' end='00' name='j' step='-2' comparison='gt'> <tr><td>{$j}</td><td>abc</td></tr> </for> </table> <br> <volist name='list' id='v'> {$v.username}<br/> </volist> </body> </html> //遍历数组 <?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ $user=M('user'); //返回数组 $arr=$user->select(); dump($arr); $this->assign('list',$arr); $this->display(); } } <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>--> <!--<script src='__PUBLIC__/Js/test.js'></script>--> <!--<import type='css' File='Css.test'/> <import type='js' File='Js.test'/>--> <title>Document</title> </head> <body> <table border='1' > <foreach name='list' item='v'> <tr> <td>{$v.id}</td> <td>{$v.username}</td> <td>{$v.password}</td> <if condition="$v.sex eq 1" > <td>男</td> <else/> <td>女</td> </if> </tr> </foreach> </table> </body> </html>