欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php之smarty分配变量

程序员文章站 2024-01-18 08:15:52
...
smarty2.php

require('Smarty/Smarty.class.php');
   require './smarty.inc.php';
   global $_smarty;

   $_title = 'Smarty模板引擎';
   $_smarty->assign('title', $_title);
   $_array = array('aaa', 'bbbb', 'ccc', 'dddd');
   $_array2 = array('haha'=>'aaa', 'hehe'=>'bbbb', 'lala'=>'ccc', 'xixi'=>'dddd');
   $_array3 = array(
   			array('haha', 'ssss'),
			array('lala','ssdvs'),
			array('ewef','wefwa')
   );
    $_array4 = array(
   			'aa'=>array('haha', 'ssss'),
			'bb'=>array('lala','ssdvs'),
			'cc'=>array('ewef','wefwa')
   );

   class People
   {
      public $_name = 'nini';
	  public function _run()
	  {
	     return 'running....';
	  }
   };
   $_smarty->assign('array', $_array);
   $_smarty->assign('array2', $_array2);
   $_smarty->assign('array3', $_array3);
   $_smarty->assign('array4', $_array4);
   $_smarty->assign('people', new People());
   $_smarty->display('demo2.tpl');

   //phpinfo();
?>

demo2.tpl

{config_load file='webconfig.config'}


  {$title}

hi,{$name} Welcome to website!!!
{$array[2]}
{$array2.hehe}
{$array3[2][0]}
{$array4.bb[1]}
{$people->_name} {$people->_run()}
{$smarty.config.webname} {#weburl#}
{$smarty.get.name}

访问地址:http://127.0.0.1/smarty2.php?name=hahahahaha

以上就介绍了php之smarty分配变量,包括了require方面的内容,希望对PHP教程有兴趣的朋友有所帮助。