smarty

smarty半小时快速上手教程

余生长醉 提交于 2020-03-01 02:59:35
smarty的程序设计部分 : 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计。下载Smarty文件放到你们站点中。 index.php PHP代码: <?php /** * * @version $Id: index.php * @package * @author www.php100.com * @action 显示实例程序 */ include_once("./Smarty/Smarty.class.php"); //包含smarty类文件 $smarty = new Smarty(); //建立smarty实例对象$smarty $smarty->templates("./templates"); //设置模板目录 $smarty->templates_c("./templates_c"); //设置编译目录 $smarty->cache("./cache"); //缓存目录 $smarty->cache_lifetime = 0; //缓存时间 $smarty->caching = true; //缓存方式 $smarty->left_delimiter = "{#"; $smarty->right_delimiter = "#}"; $smarty->assign(

smarty中foreach的用法

安稳与你 提交于 2020-03-01 02:32:07
{foreach},{foreachelse} {foreach} 用于像循环访问一个数字索引数组一样循环访问一个关联数组,与仅能访问数字索引数组的{section}不同,{foreach}的语法比 {section}的语法简单得多,但是作为一个折衷方案也仅能用于单个数组。每个{foreach}标记必须与关闭标记{/foreach}成对出现。 属性 1、 from 类型:array数组 必要性:Yes必要默认值:n/a 描述:循环访问的数组 2、 item 类型:string字符串 必要性:Yes必要 默认值:n/a 描述:当前元素的变量名 3、 key 类型:string字符串 必要性:No可选 默认值:n/a 描述:当前键名的变量名 4、 name 类型:string字符串 必要性:No可选 默认值:n/a 描述:用于访问foreach属性的foreach循环的名称 from和item是必要属性 {foreach}循环的name可以是任何字母,数组,下划线的组合,参考PHP变量。 {foreach}循环可以嵌套,嵌套的{foreach}的名称应当互不相同。 from属性通常是值数组,被用于判断{foreach}的循环次数。 在from变量中没有值时,将执行{foreachelse}。 {foreach}循环也有自身属性的变量,可以通过{$smarty.foreach.name

smarty中如何遍历一维数组跟二维数组

不问归期 提交于 2020-02-29 12:42:36
(1)一维数组 可以使用foreach. 比如: 数组:$addr = array( '01' => '广州', '02' => '韶关', 狗蛋大智慧2011版下载 '03' => '深圳', '04' => '珠海', '05' => '汕头', '06' => '佛山', '53' => '云浮', '52' => '揭阳', '51' => '潮州', '20' => '中山', '19' => '东莞', '07' => '江门', '08' => '湛江', '09' => '茂名', '12' => '肇庆', '13' => '惠州', '14' => '梅州', '15' => '汕尾', '16' => '河源', '17' => '阳江', '18' => '清远' ); 可以通过 <!--{foreach from=$addr item=addre}--> <option value="<!--{$addre}-->"><!--{$addre}--></option> <!--{/foreach}--> 输出 PS. 如果是$array = array('value1','value2');这种形式的数组,也可以通过 {section name=id loop=$array} {$array[id]} {/section} 输出 (2)二维数组:

php composer的学习之路

不羁岁月 提交于 2020-02-23 05:40:16
composer的介绍请看这里 http://docs.phpcomposer.com/00-intro.html composer的安装过程我就不介绍了,windows系统下跟其他安装没区别,一直下一步就行了。 安装完后我们去查看有没有安装成功 运行cmd,打开命令窗口,输入composer -v,出现一下内容证明安装成功: 否则会提示错误信息。 之后我们需要将它配置成国内镜像输入这个命令即可: composer config -g repo.packagist composer https://packagist.phpcomposer.com 复制进去就好 好了之后我们看看怎么引入库文件吧: 首先我们要在项目的根目录中新建一个composer.json的文件; 让后我们知道我们引入的库的库名和版本号,首先去这个网站去搜索去查看 https://packagist.org/ 比如我们要安装smarty,我们就搜索smarty 出来了,我们点击第一个查看详细信息,由于该网站是国外的,会比较慢,耐心等待吧; 下面也有使用方法可以自己翻译看看,我就不介绍了; 知道库名和版本号之后我们打开刚刚新建的文件输入一下代码: { "require": { "smarty/smarty": "3.1.21" } } 好了之后,继续打开我门命令窗口,先要去到我们项目的根目录下,然后输入

php模板引擎-smarty

☆樱花仙子☆ 提交于 2020-02-14 22:05:05
一、认识smarty 1 require_once("./smarty/libs/Smarty.class.php"); 2 $smarty = new Smarty(); 3 4 $smarty->assign("name", 'lxwwwih'); 5 6 $smarty->assign("age", 25); 7 8 $smarty->display("view.html"); 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 姓名:{$name} 9 年龄:{$age} 10 </body> 11 </html> 二、配置smarty   1、css中样式body{backround-color:#fff}, 会有冲突     $smarty->left_delimiter = "<{";     $smarty->right_delimiter = "}>";   2、常用的目录的配置     ①设置视图文件的目录       $smarty->setTemplateDir("新的目录路径");       $smarty->getTemplateDir(); 1 require_once(".

smarty模版--if操作符

£可爱£侵袭症+ 提交于 2020-02-01 03:24:16
1,smarty模版中if的用法 <?php $root=str_replace("\\","/",dirname(__FILE__)); define("ROOT",$root."/"); define("DOMAIN","http://localhost/testSmarty"); require(ROOT."smarty/Smarty.class.php"); $smarty=new Smarty(); $smarty->template_dir=ROOT."demo/templates/"; $smarty->compile_dir=ROOT."demo/templates_c/"; $smarty->use_sub_dirs=false; $smarty->left_delimiter="<{"; $smarty->right_delimiter="}>"; $smarty->caching="0"; $smarty->cache_dir=ROOT."demo/caches/"; $smarty->cache_lifetime=3*24*(60*60);//0 $smarty->assign("num",33); $smarty->display("testif.html"); ?> 模版文件:testif.html <{if $num eq 22}> 这部分执行了22

Filter results based on the select box selected value

眉间皱痕 提交于 2020-01-25 11:53:19
问题 I have been searching for quite some time, but I still haven't found a decent answer to my question. I'm trying to filter my results based on the value what the user will select from the selectbox. However selectbox is populated from the database and it's lenght varies. First select entry will be an empty one, so all of the matching values will be displayed. But when a different value has been selected from the selectbox all the non-matching itmes need to dissapear. Easyest way to do that is

Updating theme.yml in PrestaShop

∥☆過路亽.° 提交于 2020-01-23 11:44:31
问题 So I'm trying to modify the layout of theme.yml in a PrestaShop theme. I comment out the following: hooks: modules_to_hook: displayFooter: # - ps_linklist # - ps_customeraccountlinks - ps_contactinfo And then I save and FTP the file. The FTP succeeds. However, the linklist and customeraccountlinks hooks are still displayed in the footer on client browsers. I've tried to force refresh on the client browser, also to clear cache in back office. Neither of these work. How do I propagate this

将smarty安装到MVC架构中

∥☆過路亽.° 提交于 2020-01-16 16:46:59
首先是composer.json { "require": { "smarty/smarty": "^3.1" }, // 自动加载 // 可以在composer.json的autoload字段找那个添加自己的autoloader "autoload": { "psr-4": { "App\\Controllers\\": "Controllers/", "App\\Models\\": "Models/", "Tools\\": "Tools/" } } } Models/Users.php <?php // model层数据库操作演示 namespace App\Models; class Users { // 数据存入数据库演示 public function store() { echo 'store into database'; } // 查询数据库演示 public function getUsername() { // 查询数据库 return 'test-data'; } } Controllers/UserController.php <?php namespace App\Controllers; use App\Models\Users; use Smarty; class UserController extends Smarty { public

MVC开发模式以及Smarty模板引擎的使用

无人久伴 提交于 2020-01-16 16:25:15
Linux 全局安装 composer 将目录切换到/usr/local/bin/目录 cd /usr/local/bin/ 在 bin 目录中下载 composer curl -sS https://getcomposer.org/installer | php 通过 composer.phar -v 查看 composer 修改为中国镜像 composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com 最后我把composer.phar复制了一份,重命名为composer 以后可以直接用composer MVC架构模式 控制器(Controller)- 负责转发请求,对请求进行处理 视图(View) - 界面设计人员进行图形界面设计 模型(Model) - 程序员编写程序应有的功能(实现算法等等)、数据库专家进行数据管理和数据库设计(可以实现具体的功能) 实现简易模板引擎: composer.json { // 自动加载 // 可以在composer.json的autoload字段找那个添加自己的autoloader "autoload": { "psr-4": { "App\\Controllers\\": "Controllers/", "App\\Models\\":