Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement smarty template engine to assign data types

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to achieve smarty template engine allocation of data types", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to achieve smarty template engine allocation of data types" bar!

The specific analysis is as follows:

I. Distribution of basic data

/ / assign basic data $smarty- > assign ("str", "hello smarty!"); $smarty- > assign ("int", 12.1344); $smarty- > assign ("double", 12.1344); $smarty- > assign ("bool", true); $smarty- > assign ("bool2", false); string type: integer: floating point: Boolean true: Boolean false:

The browser displays the results:

1 for true, 0 for false, false for null, showing nothing.

Second, allocate the array of composite data

/ / indexed array $res=array ('Shanghai', 'Beijing', 'Shenzhen'); $smarty- > assign ("arr", $res); / associative array $res2=array ('city1'= >' Beijing', 'city2'= >' Guangzhou', 'city3'= >' Hunan'); $smarty- > assign ("arr2", $res2); / / indexed 2D array $res3 = array ('Xiaoxiao', 'Changshan','Wu Bei'), array ('Shanshan', 'Chang Ming') $smarty- > assign ("arr3", $res3); / / the associated two-dimensional array $res4 = array (array ('id'= >' 001), email'= > 'zhangsan@1163.com'), array (' url'= > 'http://www.baidu.com','age'=>'28')); $smarty- > assign ("arr4", $res4) / / an associative 2D array of 2 $res5=array ('emp1'= > array (' id'= > '001'), email'= > 'zhangsan@1163.com'),' emp2'= > array ('url'= >' http://www.baidu.com','age'=>'28')); $smarty- > assign ("arr5", $res5)

Template file

Indexed array: element 1, element 2, element 3: associative array 1 (not recommended): element 1, element 2, element 3: associative array, element 2 (recommended): element 1, element 2, element 3: two-dimensional indexed array: element 1, element 2, element 3: element 1, element 2, element 3, element 4, element 5: associative two-dimensional array form 1: id-, name-, email- Url-, age- associative two-dimensional array form 2: id-, name-, email-, url-, age-

The browser displays the results:

Third, the object of assigning compound data

Class Master {var $name; var $age; function _ _ construct ($name,$age) {$this- > name=$name; $this- > age=$age;}} class Dog {var $name; var $age; var $color; var $arr; var $master; function _ construct ($name,$age,$color,$arr6,$master) {$this- > name=$name; $this- > age=$age; $this- > color=$color; $this- > arr=$arr6; $this- > master=$master;} $arr6=array $dog1 = new Dog ('Xiaobai', 1MagneWhitekeeper Magnum Arr6 magic master); $smarty- > assign ("dog", $dog1)

Template file

Object: / / basic properties name-name} >, age-age} >, color-color} > / / array properties arr-arr [0]} >, arr-arr [1]} >, arr-arr [2]} > / / object properties object-master- > name} >, object-master- > age} >

The browser displays the results

Thank you for your reading, the above is "how to achieve smarty template engine allocation of data types" content, after the study of this article, I believe you on how to achieve smarty template engine allocation of data types of this problem has a deeper understanding, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report