T086ѧϰ�� | վ��ѧԺ | �����ĵ� | ���� | Ъ���� | IP��ַ��ѯ | �������� | ���ջ��� | �����ֵ� | ���ù��� | ������Ϣ��ѯ

��ש����ϵ�� -- smarty��������

�� �������ߣ�PHPchina dreamriver ����ʱ�䣺2009-06-26 | ���壺�� �� С��
[����]����smarty�ṩ��ǿ���Ļ��湦�ܡ�����ʱ���Dz���ϣ����ƪ�ĵ��������棬������ѡ���Ļ���ijһ�������ݻ�ijһ�������ݲ������档��������ҳ���϶�ʹ��һ�����й�����λ�õ�ģ�壬���������԰����κ�HTML��ͼ����FLAS...

����smarty�ṩ��ǿ���Ļ��湦�ܡ�����ʱ���Dz���ϣ����ƪ�ĵ��������棬������ѡ���Ļ���ijһ�������ݻ�ijһ�������ݲ������档��������ҳ���϶�ʹ��һ�����й�����λ�õ�ģ�壬���������԰����κ�HTML��ͼ����FLASH�Ȼ�����Ϣ. �������ﲻ��ʹ��һ����̬�����ӣ�ͬʱ����Ҳ��ϣ���ù�����������. ������Ҫ�� insert ����ָ����ͬʱ��Ҫһ������ȡ��������������Ϣ��smartyҲ�ṩ�����ֻ�������������

�������ǿ���ʹ��{insert}ʹģ����һ���ֲ�������

��������ʹ��$smarty-��register_function($params,&$smarty)��ֹ�����ӻ�����������

����������ʹ��$smarty-��register_block($params,&$smarty)ʹ��ƪҳ���е�ijһ�鲻�����档

����������������һ���������󣬷ֱ�˵�������ֿ��ƻ��������ķ�����

�������󣺱��������ĵ��е�ǰʱ�䲻�����棬��ÿ��ˢ�¶��仯��

����1��ʹ��insert����ʹģ����һ���ֲ�������

����index.tpl:

������div��{insert name="get_current_time"}��/div��

����index.php

����function insert_get_current_time(){

���� return date("Y-m-d H:m:s");

����}

����$smarty=new smarty();

����$smarty-��caching = true;

����if(!$smarty-��is_cached()){

���� .......

����}

����$smarty-��display('index.tpl');

����ע�⣺

��������һ����������������ʽΪ��inser_name(array $params, object &$smarty),����������ѡ�ģ�������ģ����insert��������Ҫ�����������ԣ��ͻ���Ϊ���鴫�ݸ��û������ĺ�����

�����磺{insert name='get_current_time' local='zh'}

������get_current_time���������ǾͿ���ͨ��$params['local']����������ֵ��

����������get_current_time��������Ҫ�õ���ǰsmarty�����ķ��������ԣ��Ϳ���ͨ���ڶ����������á�

������ʱ���ᷢ��index.tpl�ѱ����棬����ǰʱ��ȴ��ÿ��ˢ���ڲ��ϱ仯��

����2��ʹ��register_function��ֹ�����ӻ���������

����index.tpl:

������div��{current_time}{/div}

����

����index.php:

����function smarty_function_current_time($params, &$smarty){

���� return date("Y-m-d H:m:s");

����}

����

����$smarty=new smarty();

����$smarty-��caching = true;

����$smarty-��register_function('current_time','smarty_function_current_time',false);

����if(!$smarty-��is_cached()){

���� .......
����}

����$smarty-��display('index.tpl');


����ע�⣺

��������һ����������������ʽΪ��smarty_type_name($params, &$smarty)

����typeΪfunction

����nameΪ�û��Զ�����ǩ���ƣ���������{current_time}

�������������DZ����ģ���ʹ�ں�����û��ʹ��ҲҪд�ϡ����������Ĺ���ͬ�ϡ�

����3��ʹ��register_blockʹ��ƪҳ���е�ijһ�鲻������

����index.tpl:

������div align='center'��

����Page created: {"0"��date_format:"%D %H:%M:%S"}

����{dynamic}

����Now is: {"0"��date_format:"%D %H:%M:%S"}

����... do other stuff ...

����{/dynamic}

������/div��

����index.php:

����function smarty_block_dynamic($param, $content, &$smarty) {

����return $content;

����}
����$smarty = new Smarty;

����$smarty-��caching = true;

����$smarty-��register_block('dynamic', 'smarty_block_dynamic', false);

����if(!$smarty-��is_cached()){

���� .......

����}

����$smarty-��display('index.tpl');

����ע�⣺

��������һ����������������ʽΪ��smarty_type_name($params, &$smarty)

����typeΪblock

����nameΪ�û��Զ�����ǩ����,��������{dynamic}

�������������DZ����ģ���ʹ�ں�����û��ʹ��ҲҪд�ϡ����������Ĺ���ͬ�ϡ�

����4���ܽ�

������1���Ի����Ŀ���������

����ʹ��register_function��register_block�ܹ������Ŀ��Ʋ��������Ļ�������������ͨ�����������������Ƿ񻺴棬Ĭ���ǻ����ģ���Ҫ������ʾ����Ϊfalse���������������е�������������$smarty-��register_function('current_time','smarty_function_current_time',false);��

������insert����Ĭ���Dz������ġ������������Բ����޸ġ������������Ͻ�insert�����Ի����Ŀ��������ƺ�����register_function��register_blockǿ��

������2��ʹ�÷����ԣ�

��������insert����ʹ�÷dz����㡣������ʾע�ᣬֻҪ�ڵ�ǰ���������а�����������smarty�ͻ��Զ��ڵ�ǰ�����Ĺ����в���ָ���ĺ�����

������Ȼregister_functionҲ����������������ʱ��ʾע�ᡣ������������Ч��������ģ�溯��һ����ͳͳ�����棬���Ҳ��ܿ��ơ�

����������ʹ��������ʱ��ʾ����register_functionע���Զ��庯������ôһ��Ҫ�ڵ���is_cached()����ǰ���ɺ�����ע�Ṥ����

����������is_cached()��һ�������ĵ�����Ϊ�Ҳ���ע�ắ��������smarty������

  • ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
  • �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
������ѯ Health Check Gulangyu
© 2017 T086ѧϰ�� - T086.com(ԭitlearner.com)
RunTime:8.44ms QueryTime:7