在smart模板中模板赋值的js函数给全局变量赋值是什么???

php 中sql语句带参数 smart中怎么赋值_百度知道
php 中sql语句带参数 smart中怎么赋值
我有更好的答案
你述说清楚点SQL带参数和smarty有关吗?
php文件中方法sql语句有参数
smart模板怎么调用方法怎么赋值
为您推荐:
其他类似问题
sql语句的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。[模板 下载地址更新] SmartTemplate(适用于企业级PHP开发的模板引擎)
[模板 下载地址更新] SmartTemplate(适用于企业级PHP开发的模板引擎)
企业级PHP开发,我们需要考虑:
•& & & & 质量 (程序必须拥有一致性和稳定性)
•& & & & 功能 (程序必须满足付费用户的所有功能需求)
•& & & & 性能 (程序应该在一个可接受的严格规定的时间内处理用户请求)
•& & & & 扩展性 (倘若硬件支持,程序使用用户必须有数量级的提升)
•& & & & 持续发展 (不能超过被期望的开发预算)
•& & & & 准时性 (程序必须在规定的时间交付)
•& & & & 维护/支持费用 ()
•& & & & 可用性
•& & & & ......
•& & & & 等等
简短说明:
主要翻译的SmartTemplate部分的内容,随着认识的逐次加深,我将适当调整翻译的结果。
如果你有任何建议,请告诉我,谢谢!
为什么推荐他:
•& & & & 轻巧
•& & & & 简单
•& & & & 功能确实不错
访问网址:
现在下载:
基本方法:
& &• assign
& &• append
& &• output
& &• result
& &• use_cache
& &• debug
模板流程控制:
& &• if
& &• else
& &• elseif
& &• begin ... end(块结构)
昵称: HonestQiao &时间:
CODE:Hello World!现在我们来看看达到我们期望的页面版式的HTML源代码:
HTML-源代码 (hello_world.html):CODE:&HTML&;
&H3&;Hello World!&/H3&;
&/HTML&;然后开始令人激动的一步: 分离内容和设计. 我们把HTML源代码之中的内容元素替换为模板占位符. 模板占位符被分配一个唯一的名称并且使用一个特有的标签包含起来,这样我们在随后的程序之中可以识别他们. 标题 Hello World! 被替换为一个叫做TITLE 的占位符. 我们是用大括弧来标记占位符, 似的我们的模板引擎可以发现: {TITLE}. 最后HTML模板如下:
HTML-模板 (hello_world.tpl.html):CODE:&HTML&;
&H3&;{TITLE}&/H3&;
&/HTML&;使内容整合到模板,我们需要做如下工作:
&& & & & 调用 SmartTemplate 类
&& & & & 创建一个 SmartTemplate 分析器 对象
&& & & & 告诉 SmartTemplate 要使用的HTML模板
&& & & & 指定内容给关联的占位符
&& & & & 处理模板
&& & & & 输出结果
以下的PHP程序完成所需的工作:
hello_world.php:CODE:&?php
& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&hello_world.tpl.html&);
& & $page-&;assign('TITLE', 'Hello World!');
& & $page-&;output();
?&;就这么简单 – 我们的 Hello World 例程已经准备运行了.
昵称: HonestQiao &时间:
昵称: HonestQiao &时间:
昵称: HonestQiao &时间:
CODE:&?php
& & $template&&=&&new SmartTemplate('template.html');
& & $text&&=&&'Sample Text';
& & $template-&;assign( 'TITLE', $text );
& & $template-&;output();
?&;模板(template.html):CODE:&html&; {TITLE} &/html&;输出:CODE:&html&; Sample Text &/html&;例子2: 多个标量赋值CODE:&?php
& & $template&&=&&new SmartTemplate('user.html');
& & $template-&;assign( 'NAME',&&'John Doe' );
& & $template-&;assign( 'GROUP', 'Admin'& & );
& & $template-&;assign( 'AGE',& &'42'& && & );
& & $template-&;output();
?&;模板(user.html):CODE:Name: {NAME}
Group: {GROUP}
Age:& &{AGE}输出:CODE:Name:&&John Doe
Group: Admin
Age:& &42例子3: 使用数组给多个标量赋值CODE:&?php
& & $user&&=&&array(
& && && && && &&&'NAME'&&=&; 'John Doe',
& && && && && &&&'GROUP' =&; 'Admin',
& && && && && &&&'AGE'& &=&; '42',
& && && && &&&);
& & $template&&=&&new SmartTemplate('user.html');
& & $template-&;assign( $user );
& & $template-&;output();
?&;模板(user.html):CODE:Name:&&{NAME}
Group: {GROUP}
Age:& &{AGE}输出:CODE:Name:&&John Doe
Group: Admin
Age:& &42例子4: 命名空间CODE:&?php
& & $admin&&=&&array(
& && && && && && & 'NAME'&&=&; 'John Doe',
& && && && && && & 'AGE'& &=&; '42',
& && && && && &);
& & $guest&&=&&array(
& && && && && && & 'NAME'&&=&; 'Roger Rabbit',
& && && && && && & 'AGE'& &=&; '16',
& && && && && &);
& & $template&&=&&new SmartTemplate('users.html');
& & $template-&;assign( 'admin', $admin );
& & $template-&;assign( 'guest', $guest );
& & $template-&;output();
?&;模板(user.html): 占位符(PLACEHOLDER)对应数组,“.”对应数组“[]”CODE:Admin Name: {admin.NAME}
Admin Age:&&{admin.AGE}
Guest Name: {guest.NAME}
Guest Age:&&{guest.AGE}输出:CODE:Admin Name: John Doe
Admin Age:&&42
Guest Name: Roger Rabbit
Guest Age:&&16例子5: 使用数组命名空间CODE:&?php
& & $users&&=&&array(
& && && && && && & 'admin' =&; array(
& && && && && && && &&&'NAME'&&=&; 'John Doe',
& && && && && && && &&&'AGE'& &=&; '42',
& && && && && && & ),
& && && && && && & 'guest' =&; array(
& && && && && && && &&&'NAME'&&=&; 'Roger Rabbit',
& && && && && && && &&&'AGE'& &=&; '16',
& && && && && && & ),
& && && && && &);
& & $template&&=&&new SmartTemplate('users.html');
& & $template-&;assign( $users );
& & $template-&;output();
?&;模板(user.html): 占位符(PLACEHOLDER)对应数组,“.”对应数组“[]”CODE:Admin Name: {admin.NAME}
Admin Age:&&{admin.AGE}
Guest Name: {guest.NAME}
Guest Age:&&{guest.AGE}输出:CODE:Admin Name: John Doe
Admin Age:&&42
Guest Name: Roger Rabbit
Guest Age:&&16例子6: 命名空间, 3个部分CODE:&?php
& & $template&&=&&new SmartTemplate('template.html');
& & $content['world']['europe']['germany']&&=&&'DE';
& & $template-&;assign( 'top_level_domain', $content );
& & $template-&;output();
?&;模板(template.html): 占位符(PLACEHOLDER)对应数组,“.”对应数组“[]”CODE:&html&; German TLD: {top_level_domain.world.europe.germany} &/html&;输出:CODE:&html&; German TLD: DE &/html&;例子7: 列表赋值CODE:&?php
& & $links&&=&&array(
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'PHP',
& && && && && && && &&&'URL'& &=&; 'http://www.php.net/',
& && && && && && & ),
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'Apache',
& && && && && && && &&&'URL'& &=&; 'http://www.php.net/',
& && && && && && & ),
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'MySQL',
& && && && && && && &&&'URL'& &=&; 'http://www.mysql.com/',
& && && && && && & ),
& && && && && &);
& & $template&&=&&new SmartTemplate('links.html');
& & $template-&;assign( 'links', $links );
& & $template-&;output();
?&;模板(links.html): 结构名称lnks对应数组CODE:&html&;
&h3&; Sample Links &/h3&;
&!-- BEGIN links --&;
& & &a href=&{URL}&&; {TITLE} &/a&;
&!-- END links --&;
&/html&;输出:CODE:&html&;
&h3&; Sample Links &/h3&;
& & &a href=&http://www.php.net/&&; PHP &/a&;
& & &a href=&http://www.apache.org/&&; Apache &/a&;
& & &a href=&http://www.mysql.com/&&; MySQL &/a&;
&/html&;Example 8: 使用数组于多个命名空间CODE:&?php
& & $title&&=&&'Sample Links';&&//&&Page Title
& & $target =&&'_blank';& && &&&//&&The Same Target for all links
& & $links&&=&&array(
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'PHP',
& && && && && && && &&&'URL'& &=&; 'http://www.php.net/',
& && && && && && & ),
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'Apache',
& && && && && && && &&&'URL'& &=&; 'http://www.php.net/',
& && && && && && & ),
& && && && && && & array(
& && && && && && && &&&'TITLE' =&; 'MySQL',
& && && && && && && &&&'URL'& &=&; 'http://www.mysql.com/',
& && && && && && & ),
& && && && && &);
& & $template&&=&&new SmartTemplate('links.html');
& & $template-&;assign( 'TITLE', $title );
& & $template-&;assign( 'TARGET', $target );
& & $template-&;assign( 'links',&&$links&&);
& & $template-&;output();
TITLE 与 links..TITLE 使用不同的命名空间!
TARGET 不是 links 数组的成员. 如果使用在 BEGIN..END 块之内, 他必须被引用为 {parent.TARGET} 或者 {top.TARGET}.
其他可能的用法:
{top.TITLE}, {parent.parent.PAGE_ID}, {top.users.ADMIN}, 等等..
模板(links.html):CODE:&html&;
&h3&; {TITLE} &/h3&;
&!-- BEGIN links --&;
& & &a target='{parent.TARGET}' href=&{URL}&&; {TITLE} &/a&;
&!-- END links --&;
&/html&;输出:CODE:&html&;
&h3&; Sample Links &/h3&;
& & &a target=&_blank& href=&http://www.php.net/&&; PHP &/a&;
& & &a target=&_blank& href=&http://www.apache.org/&&; Apache &/a&;
& & &a target=&_blank& href=&http://www.mysql.com/&&; MySQL &/a&;
昵称: HonestQiao &时间:
昵称: 北京野狼 &时间:
CODE:&?php
& & $page&&=&&new SmartTemplate('links.html');
& & $page-&;append('links' =&; array(
& && && && && && && && && && && &'TITLE' =&; 'PHP',
& && && && && && && && && && && &'URL'& &=&; 'http://www.php.net/'
& && && && && && && && && &&&));
& & $page-&;append('links' =&; array(
& && && && && && && && && && && &'TITLE' =&; 'Apache',
& && && && && && && && && && && &'URL'& &=&; 'http://www.apache.org/'
& && && && && && && && && &&&));
& & $page-&;append('links' =&; array(
& && && && && && && && && && && &'TITLE' =&; 'MySQL',
& && && && && && && && && && && &'URL'& &=&; 'http://www.mysql.com/'
& && && && && && && && && &&&));
& & $page-&;output();
?&;模板(links.html): 列表追加为行CODE:&html&;
&h3&; Sample Links &/h3&;
&!-- BEGIN links --&;
& & &a href=&{URL}&&; {TITLE} &/a&;
&!-- END links --&;
&/html&;输出:CODE:&html&;
&h3&; Sample Links &/h3&;
& & &a href=&http://www.php.net/&&; PHP &/a&;
& & &a href=&http://www.apache.org/&&; Apache &/a&;
& & &a href=&http://www.mysql.com/&&; MySQL &/a&;
例子2 (标量):CODE:&?php
& & $page&&=&&new SmartTemplate('template.html');
& & $page-&;append('TITLE' =&; 'Hello ');
& & $page-&;append('TITLE' =&; 'World ');
& & $page-&;append('TITLE' =&; '!');
& & $page-&;output();
?&;模板(template.html): 标量为内容的追加CODE:&html&; {TITLE} &/html&;输出:CODE:&html&; Hello World ! &/html&;
昵称: HonestQiao &时间:
昵称: imbiss &时间:
原帖由 &imbiss& 发表:
有意思。&他把html模板转换为php脚本以获得快速的运行速度&
是否就是说,他需要往硬盘里写东西?权限如何处理?
期待尝试一次。你说的东东,对应这个选项,转换后的php脚本会保存在这个目录下:
string $temp_dir
模板编译保存目录,默认为/tmp/
可使用全局变量$_CONFIG['smarttemplate_compiled']设置
注意:确保PHP对该目录可写
昵称: titan3 &时间:
CODE:&?php
& & $page&&=&&new SmartTemplate('template.html');
& & $page-&;assign('TITLE' =&; 'Sample Title');
& & $page-&;output();
昵称: HonestQiao &时间:
CODE:&?php
& & $page&&=&&new SmartTemplate('template.html');
& & $page-&;assign('TITLE' =&; 'Sample Title');
& & $output&&=&&$page-&;result();
& & echo 'Output page: ' . $
昵称: HonestQiao &时间:
CODE:&?php
& & $page&&=&&SmartTemplate('template.html');
& & $page-&;cache_dir& && & =&&'/tmp/';&&//&&Where to store cache files
& & $page-&;cache_lifetime&&=&&120;& && &//&&Keep cache for 120 seconds
& & $page-&;use_cache();& && && && && &&&//&&Activate ouput cache
& & //&&Assemble Page Content
& & $page-&;output();
昵称: HonestQiao &时间:
昵称: HonestQiao &时间:
CODE:&!-- IF var --&; var 不为空! &!-- ENDIF var --&;变量值判断CODE:&!-- IF name==&HonestQiao& --&; Your name is HonestQiao! &!-- ENDIF name --&;变量值否定判断CODE:&!-- IF name!=& HonestQiao & --&; Your name is not HonestQiao! &!-- ENDIF name --&; (var 在 ENDIF 之后是可选的,但是最好加上)
if.php: (&&Download)CODE:&?php
& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&if.html&);
& & $page-&;assign( 'username',& &'HonestQiao' );
& & $page-&;assign( 'usergroup',&&'ADMIN' );
& & $page-&;assign( 'picture',& & '' );
& & $page-&;output();
?&; if.php使用的模板文件如下:
if.html: (&&Download)CODE:&!-- IF username --&; &H3&; Welcome, {username} &/H3&; &!-- ENDIF --&;
&!-- IF picture --&; &img src=&{picture}&&; &!-- ENDIF picture --&;
&!-- IF usergroup=&ADMIN& --&;
&a href=&admin.php&&; ADMIN Login &/a&;&br&;
&!-- ENDIF usergroup --&;if.php执行的效果如下:
输出: (&&查看)CODE:&H3&; Welcome, HonestQiao &/H3&;
&a href=&admin.php&&; ADMIN Login &/a&;&br&;
昵称: HonestQiao &时间:
CODE:&?php
& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&else.html&);
& & $page-&;assign( 'username',& &'John Doe' );
& & $page-&;assign( 'usergroup',&&'ADMIN' );
& & $page-&;assign( 'picture',& & '' );
& & $page-&;output();
?&; else.php使用的模板文件如下:
else.html: (&&Download)CODE:&!-- IF username --&;
&H3&; Welcome, {username} &/H3&;
&!-- ENDIF --&;
&!-- IF picture --&;
&img src=&{picture}&&;
&!-- ELSE --&;
Picture not available! &br&;
&!-- ENDIF picture --&;
&!-- IF usergroup=&ADMIN& --&;
&a href=&admin.php&&; ADMIN Login &/a&;&br&;
&!-- ELSE --&;
You are in guest mode!
&!-- ENDIF usergroup --&;else.php执行的效果如下:
输出: (&&查看)CODE:&H3&; Welcome, John Doe &/H3&;
Picture not available! &br&;
&a href=&admin.php&&; ADMIN Login &/a&;&br&;
昵称: HonestQiao &时间:
CODE:&?php
& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&elseif.html&);
& & $page-&;assign( 'usergroup',&&'INTERNAL' );
& & $page-&;output();
?&; elseif.php使用的模板文件如下:
elseif.html: (&&Download)CODE:&!-- IF usergroup=&ADMIN& --&;
&a href=&admin.php&&; Admin Staff Login &/a&;&br&;
&!-- ELSEIF usergroup=&SUPPORT& --&;
&a href=&support.php&&; Support Staff Login &/a&;&br&;
&!-- ELSEIF usergroup --&;
&a href=&other.php&&; Standard Login &/a&;&br&;
&!-- ELSE --&;
You don't even have a usergroup!
&!-- ENDIF --&;elseif.php执行效果如下:
输出: (&&查看)CODE:&a href=&other.php&&; Standard Login &/a&;&br&;
昵称: HonestQiao &时间:
昵称: HonestQiao &时间:
昵称: Unicorn_angel &时间:
昵称: Unicorn_angel &时间:
昵称: HonestQiao &时间:
昵称: wing-qiang &时间:
昵称: Unicorn_angel &时间:
昵称: Yarco &时间:
原帖由 &Unicorn_angel& 发表:
请教HonestQiao兄,
关于SmartTemplate模板嵌套,教程上是这样写的
有两个模板文件:
一、--table.tpl--
&p align=&center&&;&strong&..........呵呵,不知道你在什么地方看的这样子的教程?
而且你这样子的嵌套,实际上对于模板来说,非常不好。
因为你把表格的tr提取出来,这个可是很不好设计的。
而且,你没有告诉我们,你的{time}是怎么在页面占位的,实际上,你可以直接:
标准的测试,应该为:
一、--table.tpl--
&p align=&center&&;&strong&;&font color=&#FF0000& size=&5&&;{TITLE}&/font&;&/strong&;&/p&;
&p align=&center&&;--------------------------------------------------------------
&Table width=&75%& border=&1& align=&center&&;
&!-- BEGIN CONTENT --&;
&td&;{TD1}&/td&;
&td&;{TD2}&/td&;
&!-- END CONTENT --&;
--start table.php --------------------
require_once &./class/class.smarttemplate.php&;
//对表格行列数据符值
$result[]=('TD1'=&;'TD1','TD2'=&;'TD2');
//对表格整体进行赋值
$index = new SmartTemplate( &./templates/table.tpl& );
$index-&;assign ('TITLE','这是一个表格模板试验程序');
$index-&;assign('CONTENT',$result);
$index-&;output();
昵称: unixdotnet &时间:
昵称: HonestQiao &时间:
原帖由 &Unicorn_angel& 发表:
问题解决,呵,看来以后看在网站找资料先要验证一下准确性了,
开始喜欢上SmartTemplate了,呵呵,后面还有一部分,这几天不忙的时候继续帖上来。
这个东西轻巧简洁,不错
昵称: Unicorn_angel &时间:
CODE:&?php
& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&begin_end.html&);
& & $users = array(
& && && && && &array( 'NAME' =&; 'John Doe',& &'GROUP' =&; 'ADMIN' ),
& && && && && &array( 'NAME' =&; 'Jack Doe',& &'GROUP' =&; 'SUPPORT' ),
& && && && && &array( 'NAME' =&; 'James Doe',&&'GROUP' =&; 'GUEST' ),
& && && && && &array( 'NAME' =&; 'Jane Doe',& &'GROUP' =&; 'GUEST' ),
& && && && & );
& & $page-&;assign( 'users',&&$users );
& & $page-&;output();
?&; begin_end.php使用的模板如下:
begin_end.html: (&&Download)CODE:&style type=&text/css&&;
.col0 { background-color: #D0D0D0; }
.col1 { background-color: #F0F0F0; }
&table border=&1& cellpadding=&2& cellspacing=&0&&;
&th&; No &/th&;
&th&; Username &/th&;
&th&; Usergroup &/th&;
&!-- BEGIN users --&;
&tr class=&col{ROWBIT}&&;
&td&; {ROWCNT} &/td&;
&td&; {NAME} &/td&;
&td&; {GROUP} &/td&;
&!-- END users --&;
&/table&;begin_end.php的运行效果如下:
输出: (&&查看)CODE:&style type=&text/css&&;
.col0 { background-color: #D0D0D0; }
.col1 { background-color: #F0F0F0; }
&table border=&1& cellpadding=&2& cellspacing=&0&&;
&th&; No &/th&;
&th&; Username &/th&;
&th&; Usergroup &/th&;
&tr class=&col0&&;
&td&; 0 &/td&;
&td&; John Doe &/td&;
&td&; ADMIN &/td&;
&tr class=&col1&&;
&td&; 1 &/td&;
&td&; Jack Doe &/td&;
&td&; SUPPORT &/td&;
&tr class=&col0&&;
&td&; 2 &/td&;
&td&; James Doe &/td&;
&td&; GUEST &/td&;
&tr class=&col1&&;
&td&; 3 &/td&;
&td&; Jane Doe &/td&;
&td&; GUEST &/td&;
昵称: HonestQiao &时间:
CODE:......
& & & & if($AlbumAction == &List&) {
& & & & & & & & $LIST = array();
& & & & & & & & for($i=0;$i&count($Album_List)/$Album_Td;$i++)
& & & & & & & & {
& & & & & & & & & & & & for($j=0;$j&$Album_Td;$j++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & if(empty($Album_List[$i*$Album_Td+$j])) {
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & else {
& & & & & & & & & & & & & & & & & & & & $LIST[$i][&LISTTD&][$j][&LINK&] = &$Album_Url/$AlbumDir/$AlbumPage/{$Album_List[$i*$Album_Td+$j]}&;
& & & & & & & & & & & & & & & & & & & & $LIST[$i][&LISTTD&][$j][&NAME&] = &[{$Album_List[$i*$Album_Td+$j]}]&;
& & & & & & & & & & & & & & & & & & & & $LIST[$i][&LISTTD&][$j][&OBJID&] = $i*$Album_Td+$j;
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & $tpl-&;assign(&LIST&,$LIST);
& & & & & & & & $tpl-&;output();
& & & & & & & &
& & & & }& & & & & & & &
昵称: HonestQiao &时间:
昵称: Yarco &时间:
昵称: HonestQiao &时间:
昵称: nbxmedia &时间:
昵称: HonestQiao &时间:
原帖由 &nbxmedia& 发表:
说赘肉就有些过了吧..........
这玩意有些年久失修了,要拿来用肯定要做大量的修正,考虑下smartylite和savant吧
http://www.paullockaby.com/projects/smarty-light/
http://www.phpsavant.com/yawiki/呵呵,你说的用过,不过个人有一个看法,以下都是三者最基本的例子:
既然是为MVC而来得,那么把php的变量$方式,更确切的来说,用&&;,引入到模板文件,是很不明智的;
仅仅来看看模板:
savant还没有达到这个层次,似乎,因为:CODE:&?php echo $this-&;variable1 ?&;而smartylite则:CODE:&% $lala %&;我们再看看SmartTemplate:CODE:&h3&;{TITLE}&/h3&;显而易见,哪一个更适合作为模板.
当然,我用模板的目的,是为了美工和页面可以更好的承担工作.
从程序的角度来说,我也可以直接看美化的页面去确定我的变量,而不是看HTML源代码来确认变量,哪一个更便利那?
昵称: mydevc &时间:
我们再看看SmartTemplate:
&h3&;{TITLE}&/h3&;这种说法不地道吧。
phplib template也是这么写的啊。
我都不知道有什么先进性啊。
昵称: nbxmedia &时间:
原帖由 &HonestQiao& 发表:
呵呵,如果你的女友小巧玲珑,当然不会有太多的赘肉的啊。晕,这是什么话。
昵称: HonestQiao &时间:
原帖由 &hongweig& 发表:
这种说法不地道吧。
phplib template也是这么写的啊。
我都不知道有什么先进性啊。不是是否有先进性.
如果你是处在一个分工合作而不是单打独斗的环境,你可以实际问问你的页面制作人员,她更喜欢哪一个作为模板的方式.
使用&&;包含的方式,她没办法进行实际效果的预览的.
当然,如果仅仅是给PHP开发人员自己使用,那就不能这么认为了.
昵称: hongweig &时间:
原帖由 &HonestQiao& 发表:
显而易见,哪一个更适合作为模板.
当然,我用模板的目的,是为了美工和页面可以更好的承担工作.
从程序的角度来说,我也可以直接看美化的页面去确定我的变量,而不是看HTML源代码来确认变量,哪一个更便利那?美工的问题,在实际情况下是大括号更麻烦,为何?斑竹用过dreamweaverMX/2004没有?要知道&??&;和&%%&;是原生的php/asp tag,如果美工用dw这样的所见即所得工具,反而是大括号{}更容易破坏版面设计,如果您说那样的美工是不合格,那我发现80%以上的美工都是低于60分了,找一个懂smarty的美工不容易啊
而且我觉得一个标签并不是评判这个engine是否优秀的标准
昵称: hongweig &时间:
昵称: HonestQiao &时间:
原帖由 &nbxmedia& 发表:
美工的问题,在实际情况下是大括号更麻烦,为何?斑竹用过dreamweaverMX/2004没有?要知道&??&;和&%%&;是原生的php/asp tag,如果美工用dw这样的所见即所得工具,反而是大括号{}更容易破坏版面设计,如果您?.........呵呵,看来大家的意见都很多的.
一开始,我并没有说哪一个更好,只是个人看法的一个方面的而已.
使用&&;的模式,不知道你是如何在设计过程进行预览的,类似下面:
{段落标题}
吃冰淇淋和鲜澄多(不要眼红,我们就是这么开会的)开部门会议去了,回来再看.
昵称: nbxmedia &时间:
昵称: hongweig &时间:
昵称: HonestQiao &时间:
原帖由 &hongweig& 发表:
版主,我想说两句,清不要见怪:
你说的这个东东。我刚才去看了一下,我觉的版主不是太地道啊。
这个东西的功能先不要去说,
现在已经是2005年了,download页面的user comments还是2003的。
是不是这个项..........就我个人而言,我认为,没有用的东西,我是不会给大家推荐的.
[quote]原帖由 &nbxmedia&]如果网站只有一个{TITTLE}那我也不说事了,但是一旦东西多的时候在dwmx下就不太行了,特别是表格和section,foreach应用的时候,标签100%要被{var}之类的长长字符串给破坏,如果是&??&;和&%%&;,反倒只有一个很?.........[/quote 发表:
没有调查,没有发言权;就算要发言,也不能凭空意想.CODE:&HTML&;
&!-- BEGIN row --&;
&!-- 这个标签表示表格循环的起始,和DW注释相同 --&;
& & &TD&;{TITLE} &/TD&;
&!-- END row --&;
&!-- 这个标签表示表格循环的结束,和DW注释相同 --&;
&/HTML&;你需要预览效果的,你会看到,你不需要预览效果的,它只是DW的注释而已.
只有被显示的内容,才使用{}来标记.
而控制的部分,采用&!-- 控制结构 --&;来设置,绝对不会破坏版面的设计的.
不知道,你是如何猜测,他会按照你所想的进行破坏的.
不知道注释是否会破坏排版.
另外声明一下:
1,本帖介绍SmartTemplate,在本帖之中,将不可避免的在观点上更倾向她
2,可以争鸣,但是不可以争吵
昵称: hongweig &时间:
昵称: nbxmedia &时间:
原帖由 &nbxmedia& 发表:
调查?在下实在没有精力和资金对广大美工专业人士做如此有深度的&smarttemplate美工反馈调查报告&;,只是偶尔和美工吵过一下而已?
smart我用过,而且我发誓,NND我改了至少4处地方.
反正我那些美工同事看到了那..........看来分工不一样,不好类比了.
我们这里,美工出效果图并简单分割,然后页面制作成模板.
昵称: HonestQiao &时间:
昵称: nbxmedia &时间:
原帖由 &gydoesit& 发表:
如楼上所说,这玩意最后一次更新已经一两年前的事了.是不是太落后了呀.
倒是smarty还在不断更新哩.好的东西,有些会余救弥新.
实际上,咱们国内写PHP的,直接echo的人,还是很多很多的哦.
昵称: HonestQiao &时间:
昵称: gydoesit &时间:
昵称: HonestQiao &时间:
昵称: nbxmedia &时间:
原帖由 &peng1000cn& 发表:
我的网站用的就是SMART,速度很快吗?吹的,
理论上说的话,用模板要多一个过程,就是将模板转成HTML或PHP
这过程的话是需要时间的。
如果作为大型的项目的话,还是可以用的,牺牲一点点性能。从整体来看的..........你用了编译和缓存么?
昵称: peng1000cn &时间:
昵称: hongfengyue &时间:
昵称: HonestQiao &时间:
原帖由 &numlock& 发表:
当年phpe推荐的时候,好像反映没有这么强烈!
个人意见:所有的template,用处不大!
1、php本身就是一个模板系统(大家都知道,但是少有理会);
2、你的html应该使用标准化设计,页面的外观的改变要靠CSS,..........呵呵,有见解。
不过要问上句:用DW好像是用来堆砌页面的,而不是用来做标准化的页面的。
& && && && &&&不知道你是怎么进行标准化设计的?
& && && && &&&CSS控制样式,但是首先要有东西,然后CSS才有作用,没有内容,CSS巧妇难为无米之炊。
昵称: nbxmedia &时间:
昵称: numlock &时间:
昵称: powerpolly &时间:
昵称: numlock &时间:
原帖由 &numlock& 发表:
我们这里讨论的是模板引擎。不是Template View。
我说不用模板引擎,可没说不用Template View。
一个是工具,一个是模式。不要搞错,OK!既然用模板,为何不用模板引擎?这个工具用在这个模式很合适,为何不用?
昵称: imbiss &时间:
昵称: numlock &时间:
原帖由 &icelangker& 发表:
拿smartyTemplate和phplib&&来PK那个更加NB一点??
顺便问下,phplib支持cache和编译吗?smarty年轻,功能更强。(我只看过介绍,没有实战过)
phplib历史悠久,小巧,但不支持cache和所谓的&编译&. (我常用)
昵称: imbiss &时间:
原帖由 &imbiss& 发表:
smarty年轻,功能更强。(我只看过介绍,没有实战过)
phplib历史悠久,小巧,但不支持cache和所谓的&编译&. (我常用)Smarty与SmartTemplate是不同的模板。
昵称: icelangker &时间:
昵称: imbiss &时间:
昵称: HonestQiao &时间:
昵称: flowingtree &时间:
昵称: devboy &时间:
昵称: HonestQiao &时间:
原帖由 ptsmy 于
09:52 发表
版主,在你的推荐下我试用了一下smarttemplate觉得正是自己一直寻找的东西,比smarty小巧。但是我仔细看一下好像smarttemplate的cache有问题不能用,我在模板代码中也没有发现实现cache功能的代码,还请版主指点 稍后我去查看一下子。
应该是有的cache的。
昵称: vergecity &时间:
昵称: ptsmy &时间:
原帖由 ptsmy 于
09:52 发表
版主,在你的推荐下我试用了一下smarttemplate觉得正是自己一直寻找的东西,比smarty小巧。但是我仔细看一下好像smarttemplate的cache有问题不能用,我在模板代码中也没有发现实现cache功能的代码,还请版主指点 1. 这个是编译的中间文件目录,其中文件是PHP文件
$_CONFIG['smarttemplate_compiled']& & & & = SMARTTEMPLATE_ROOT . 'smarttemplate_compiled/';
2. 这个是缓存的中间文件目录,其中文件是是HTML文件
$_CONFIG['smarttemplate_cache']& & & & & & & & = SMARTTEMPLATE_ROOT . 'smarttemplate_cache/';
3. 缓存保存的时间
$_CONFIG['cache_lifetime']& & & & & & & & & & & & = 30*60*60*24;& & & & //缓存一个月
注意:目录必须可被php读写。
然后在页面之中,$page-&use_cache(),即可为当前的程序生成和使用缓存了。
一般情况时,在什么条件下,缓存会更新?可以是以下情况之一或者组合
1. POST表单提交了数据
2. WEB服务器或者客户浏览器强制更新
3. 缓存文件生存的时间达到了cache_filename
4. URI改变
可见,cache的使用是非常简单的。
$page-&use_cache()也可以使用$page-&use_cache($key)
$key可以是一个任意类型的php的变量/常量。
$key默认为空,你可以传递一个任意的参数进来作为缓存参数。
为什么使用$key?
很显而易见的使用,文章系统,showArticle.php?id=文章编号。
那么最简单的情况下,你可以使用$key=文章编号,来作为key,这样子可以缓存每一篇不同的文章。
昵称: HonestQiao &时间:
原帖由 dualface 于
13:07 发表
Smart Template 到底有用没用?
我认为基本上没什么实用价值,原因如下:
第一:功能太简单。既无法提供 Smarty 那样的扩展能力,又缺乏更新版本支持和各种插件;
反方意见:我根本用不上那么多功能啊, ... 你的意见很好,不过我仅仅针对你的这三个意见本身做一些探讨:Smart Template 到底有用没用?
我认为基本上没什么实用价值,原因如下:
第一:功能太简单。既无法提供 Smarty 那样的扩展能力,又缺乏更新版本支持和各种插件;
反方意见:我根本用不上那么多功能啊,我干嘛要用 Smarty 这个庞然大物?
我说:那你不如直接用 php 做模板得了,还要什么模板引擎啊,多此一举!
反方意见:可我要允许用户自行修改模板,这个时候嵌入 PHP 代码很危险哦!
我说:如果你的系统是允许普通用户修改模板,那么这个时候应该使用模板系统,
不过不是用 Smart Template,而是 Smarty!
首先,Smarty 提供了丰富得多的功能。
其次,你可以开发各种插件,把原本需要好几行的模板代码简化成一个标签,
例如我开发的一套 Smarty 插件,允许使用下面形式的标签:
&% CMSEntryBody title=&我的第一次& %&
就会输出标题为“我的第一次”这篇文章的内容。这样用户不但在模板里面就能
输出内容,还能控制输出什么。
这些用 Smart Template 是做不到的哦!探讨:
关于首先,这一点Smarty作为一个庞然大物,倘若没有如此优势,势必是一定的
关于其次,SmartTemplate的插件其实相当的简单和容以开发。
关于例子,SmartTemplate本身就有load_config,把你这样子类似配置的部分,直接使用一个配置文件了。第二:根本不存在什么更容易学习的神话;
反方意见:不都说了 {TITLE} &!-- IF --& 看上去比
&?php echo $title ?& &?php if ?& 更简单吗?
我说:幻觉而已!对程序员来说,模板自身的语法反倒增加了学习成本。
而对于美工来说,有必要学么?
如果要美工掌握如何嵌入循环、判断这些,和让他搞懂 &?php if else ?& 完全没区别。
可实际工作中,有几个美工能嵌代码啊?还不就是做图、切图、做成页面,
然后由程序员来嵌代码。
有人要说了:你可以教啊,教会了美工,他自己就能嵌代码了!你就解放了!
我要说:解放个屁啊!
嵌代码总要预览一下效果吧?你还得帮他在工作机上安装配置 php、mysql 这些。
如果你改了数据结构,还要记得同步到他的机器上。
最后,他不看程序能知道页面里面该嵌什么变量?
所以他还得不停的问你这个嵌什么、那个嵌什么。
如果他能看懂程序,那他还是美工么?
所以说,让美工嵌代码只是一种幻想而已!探讨:
对于程序员而言,使用任何一个模板系统,语法他都要学,这个并不是SmartTemplate的错或者缺点,但是你拿来专门说。
对于美工而言,{TITLE}这样子的方式(甚至{文章标题}),他可以很容易的看到实际的效果,而&??&的方式,势必要差一些。
所谓让美工嵌代码,那当然是幻想。但是程序和美工是可以很好的协作分工的。第三:Smart Template 的有些特征难以使用
像 Smart Template 的 cache 功能就特别难用,在面向对象的体系中如果不修改
Smart Template 自身,几乎无法将 Smart Tempalte 集成到系统中来。探讨:cache其实很简单。其他还有些细节问题也设计得不好,越用越不爽。
我以前觉得 Smart Template 小巧玲珑,挺方便的。后来做点复杂的东西才知道根本
不是那么回事。不但要改 Smart Template 自身,还要补充很多扩展功能,累啊!
所以我现在要么用 php 作模板,要么用 smarty。 探讨:
你可以说说,Smarty之中,那些非常非常复杂富有特色的部分。
也需我们可以吸取Smarty有特色而且实用的部分。
昵称: dualface &时间:
昵称: HonestQiao &时间:
原帖由 ysixin 于
14:17 发表
模板-&编译-&缓存?
有点奇怪的感觉
如果直接采用输出php变量,取消assign那一步如何? 为什么这么做?
如果你确实要这么做,那么你完全不需要类似的模板系统的。
昵称: HonestQiao &时间:
CODE:& & & & function use_cache ( $key = '' )
& & & & & & & & {
& & & & & & & & & & & &
& & & & & & & & & & & &
& & & & & & & & & & & & if (empty($_POST))
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & $this-&cache_filename&&=&&$this-&cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';
& & & & & & & & & & & &
& & & & & & & & & & & & & & & & if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache')&&&&&&($_SERVER['HTTP_PRAGMA'] != 'no-cache')&&&&&&@is_file($this-&cache_filename))
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & & & & & if ((time() - filemtime($this-&cache_filename)) & $this-&cache_lifetime)
& & & & & & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & & & & & readfile($this-&cache_filename);
& & & & & & & & & & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & ob_start( array( &$this, 'cache_callback' ) );
& & & & & & & & & & & & }
& & & & & & & & }
昵称: ysixin &时间:
CODE:$this-&cache_filename&&=&&$this-&cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';这不是很明确给出了$this-&cache_filename的生成方式么?
$this-&cache_dir来自于$_CONFIG['smarttemplate_cache']的设置,你这个设置不正确,是无法缓存的哦。
ob_start( array( &$this, 'cache_callback' ) );这个不就是调用cache_callback()来生成缓存么?
昵称: HonestQiao &时间:
CODE:&?php
& & require_once &class.smarttemplate.php&;
& & & & $_CONFIG['smarttemplate_compiled']& &='./tmp/';
& & & & $_CONFIG['smarttemplate_cache']& && &=&&'./tmp/';
& & & & $_CONFIG['cache_lifetime']& && && &&&= 30*60*60*24;& && &&&//缓存一个月
& & $page = new SmartTemplate(&Alternating_Colors.html&);
& & & & $page-&use_cache();
& & $users = array(
& && && && && &array( 'NAME' =& 'John Doe',& &'GROUP' =& 'ADMIN' ),
& && && && && &array( 'NAME' =& 'Jack Doe',& &'GROUP' =& 'SUPPORT' ),
& && && && && &array( 'NAME' =& 'James Doe',&&'GROUP' =& 'GUEST' ),
& && && && && &array( 'NAME' =& 'Jane Doe',& &'GROUP' =& 'GUEST' ),
& && && && & );
& & $page-&assign( 'users',&&$users );
& & $page-&output();
昵称: ptsmy &时间:
昵称: HonestQiao &时间:
CODE:function use_cache ( $key = '' )
& & & & //die(&test&); //有输出&test&& & & &
& & & & if (empty($_POST))
& & & & & & & & //die(&test&); //有输出&test&& & & &
& & & & & & & & $this-&cache_filename&&=&&$this-&cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';
& & & & & & & & if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache')&&&&&&($_SERVER['HTTP_PRAGMA'] != 'no-cache')&&&&&&@is_file($this-&cache_filename))
& & & & & & & & {
& & & & & & & & & & & & //die(&test&); //没有输出& & & &
& & & & & & & & & & & & if ((time() - filemtime($this-&cache_filename)) & $this-&cache_lifetime)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & readfile($this-&cache_filename);
& & & & & & & & & & & & & & & & //die(&test&); //没有输出& & & &
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & //die(&test&); //有输出&test&& & & &
& & & & & & & & ob_start( array( &$this, 'cache_callback' ) );
& & & & & & & & //die(&test&); //有输出&test&& & & &
昵称: ptsmy &时间:
昵称: HonestQiao &时间:
关于例子,SmartTemplate本身就有load_config,把你这样子类似配置的部分,直接使用一个配置文件了。load_config 和我说的自定义标签是两码事哦。我可以用这个自定义标签实现很多功能,而 load_config 仅仅是载入配置文件而已。对于程序员而言,使用任何一个模板系统,语法他都要学,这个并不是SmartTemplate的错或者缺点,但是你拿来专门说。
对于美工而言,{TITLE}这样子的方式(甚至{文章标题}),他可以很容易的看到实际的效果,而&??&的方式,势必要差一些。
所谓让美工嵌代码,那当然是幻想。但是程序和美工是可以很好的协作分工的。这点我赞成,任何模版都需要学习。当时我打那段话还有一段,可能不小心按 ctrl_z 弄丢了。也是提到 {TITLE} 这样的形式在 DW 预览起来效果更好,而 &!-- --& 来设置控制结构又不会破化页面布局。
让美工和程序员融洽协作,选择什么模版系统只是很小一个方面,重要的再于美工到底能不能理解到 HTML 标签的作用。
因为如果美工连 HTML 标签都搞不懂(很多美工只会在预览模式下画表格),那么对于修改嵌入了代码的模版自然会很头痛。
最后,我要特别说一下 Smart Template 的 use_cache()。
这个方法判断当前模版内容是否有缓存版本,如果有且没有失效,则直接读取缓存文件并输出,然后。。。。。
然后,会执行 die()。这是一个严重的设计失误!
这个问题在复杂的应用程序里面很严重。例如我需要获取生成的内容做其它用途(保存到数据库、发送电子邮件),或者在输出之后追加其它内容,那么我势必不能使用 use_cache() 方法,从而也就放弃了 Smart Template 的 cache 功能。
昵称: ptsmy &时间:
原帖由 dualface 于
22:44 发表
然后,会执行 die()。这是一个严重的设计失误!
这个问题在复杂的应用程序里面很严重。例如我需要获取生成的内容做其它用途(保存到数据库、发送电子邮件),或者在输出之后追加其它内容,那么我势必不能使用 use_cache() 方法,从而也就放弃了 Smart Template 的 cache 功能我基于smarttemplate作了一个自己用的改进版,当时也碰到这方面的问题.
在 use_cache() 中增加控制参数决定是否运行 die, 因为甚至有些时候我并不想直接 output
关于缓存(cache)方面的确有很多细节要设计, 像论坛这种东西都有一套会员系统, 就拿 CU来说, 头上都有一句 &你好, hightman ...& 那么注定这种页面就不能用 cache了. 而实际上底下的文章应该可以进行 cache .
cache 要设计好也挺复杂的. 要顾虑很多东西
昵称: HonestQiao &时间:
昵称: dualface &时间:
CODE:An optional output_callback function may be specified. This function takes a string as a parameter and should return a string. The function will be called when ob_end_flush() is called, or when the output buffer is flushed to the browser at the end of the request. When output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. If the output_callback is not a callable function, this function will return FALSE. 于是我在output()函数的include($this-&cpl_file);后面加上了ob_end_flush() ,这样在tmp目录下面就成生了缓存文件,不知道是不是这儿的问题,如果是有这个问题那这个ob_end_flush()放在哪个位置最好呢。谢谢HonestQiao
昵称: hightman &时间:
昵称: ptsmy &时间:
昵称: ptsmy &时间:
昵称: HonestQiao &时间:
昵称: sdet1234 &时间:
昵称: bs &时间:
昵称: fengye2751 &时间:
昵称: 鱼儿游 &时间:
昵称: koocy &时间:
昵称: mjdcl &时间:
昵称: carset &时间:
昵称: redaug &时间:
昵称: z-fh &时间:
昵称: yangprc &时间:
原帖由 dualface 于
22:44 发表
load_config 和我说的自定义标签是两码事哦。我可以用这个自定义标签实现很多功能,而 load_config 仅仅是载入配置文件而已。
这点我赞成,任何模版都需要学习。当时我打那段话还有一段,可能不小心按 ... 81楼的论点乔帮主还没给于回复哟..............
昵称: mark_cn &时间:
昵称: qiyu15555 &时间:
昵称: banboy &时间:
原帖由 傲枭 于
09:01 发表
以前的时候看见过没有太在意,今天要用了又回来看了一下,太好了啊!
要是有chm的手册就更好了啊 好主意,窝整一个。
昵称: 阳垭 &时间:
原帖由 HonestQiao 于
09:37 发表
好主意,窝整一个。 整完了第一个要发给我啊 呵呵
昵称: 傲枭 &时间:
昵称: HonestQiao &时间:
CODE:& ... [/quote]
append的使用正确方式是这样的,=&应该为,
[code]$page-&append('userlist',array('ID=&123','NAME'=&'Joyen'));加上include的流程控制
As of version 1.2.0 templates can be included in other templates by using the INCLUDE statement.
This permit the use of subtemplating.
The syntax is the following: &!– INCLUDE templatename.html –&
include.php:CODE:& & require_once &class.smarttemplate.php&;
& & $page = new SmartTemplate(&begin_end.html&);
& & $users = array(
& && && && && &array( 'NAME' =& 'John Doe',& &'GROUP' =& 'ADMIN' ),
& && && && && &array( 'NAME' =& 'Jack Doe',& &'GROUP' =& 'SUPPORT' ),
& && && && && &array( 'NAME' =& 'James Doe',&&'GROUP' =& 'GUEST' ),
& && && && && &array( 'NAME' =& 'Jane Doe',& &'GROUP' =& 'GUEST' ),
& && && && & );
& & $page-&assign( 'users',&&$users );
& & $page-&output();The HTML Template that is used by the PHP Script is displayed in the following box:
begin_end.html:CODE:&style type=&text/css&&
.col0 { background-color: #D0D0D0; }
.col1 { background-color: #F0F0F0; }
&table border=&1& cellpadding=&2& cellspacing=&0&&
&th& No &/th&
&th& Username &/th&
&th& Usergroup &/th&
&!-- BEGIN users --&
&tr class=&col{ROWBIT}&&
&td& {ROWCNT} &/td&
&td& {NAME} &/td&
&td& {GROUP} &/td&
&!-- END users --&
&/table&The Result that is created by the PHP Script is displayed in the following box:
Ouput:CODE:&style type=&text/css&&
.col0 { background-color: #D0D0D0; }
.col1 { background-color: #F0F0F0; }
&table border=&1& cellpadding=&2& cellspacing=&0&&
&th& No &/th&
&th& Username &/th&
&th& Usergroup &/th&
&tr class=&col0&&
&td& 0 &/td&
&td& John Doe &/td&
&td& ADMIN &/td&
&tr class=&col1&&
&td& 1 &/td&
&td& Jack Doe &/td&
&td& SUPPORT &/td&
&tr class=&col0&&
&td& 2 &/td&
&td& James Doe &/td&
&td& GUEST &/td&
&tr class=&col1&&
&td& 3 &/td&
&td& Jane Doe &/td&
&td& GUEST &/td&
昵称: 傲枭 &时间:
昵称: Joyen &时间:

我要回帖

更多关于 函数指针赋值 的文章

 

随机推荐