php smarty assigns variables

WBOY
Release: 2016-07-29 09:09:49
Original
873 people have browsed it

smarty2.php

<?php
   //<strong>require</strong>(&#39;Smarty/Smarty.class.php&#39;);
   <strong>require</strong> &#39;./smarty.inc.php&#39;;
   global $_smarty;

   $_title = &#39;Smarty模板引擎&#39;;
   $_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();
?>
Copy after login

demo2.tpl

{config_load file='webconfig.config'}
<html>

  <head><title>{$title}</title></head>
  <body>
     <p>
	    hi,{$name} Welcome to website!!!
		<br>
		{$array[2]}
		<br>
		{$array2.hehe}
		<br>
		{$array3[2][0]}
		<br>
		{$array4.bb[1]}
		<br>
		{$people->_name}
		{$people->_run()}
		<br>
		{$smarty.config.webname}
		{#weburl#}
		<br>
		{$smarty.get.name}
	 </p>
  </body>
</html>
Copy after login

Visit address: http://127.0.0.1/smarty2.php?name=hahahahaha

The above introduces the smarty allocation variables in PHP, including the require content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template