smarty

在PHP框架中需要使用smarty模板吗?

扶醉桌前 提交于 2019-12-02 05:28:52
在 java 开发中使用模板已经习以为常了,很多人讨厌 java web 开发栈中的 JSP,虽然 sun 公司推出了 JSF,但总感觉出来的不是时候,一直也没有怎么用过。在 java 网站开发教程中,SSH 中的两大框架 Struts 推荐使用 Velocity,而在 Spring 中则推荐使用 freemarker。甚至在前端语言 javascript 中都出现了各种各样的模板引擎。 在 PHP 的轻量级框架 CodeIgniter 中,明确写明: 注意:因为在视图文件中使用纯 PHP 要快一些,所以 CodeIgniter 不要求你一定要用这个类。然而,有一些开发者和对使用 PHP 有困难的设计师一同工作时,更愿意使用模板引擎。 模板是框架发展的新方向吗?使用 Smarty 呢,还是自己手写模板,或者用框架自带的。 我不少开发者认为:“就用 CI 的模板,我觉得 CI 这样的模版方式很爽”。 “模版自己写!”。 还有人觉得不应该使用模板,这些开发者主要是考虑到性能。 “最具性能的模板就是不要模板,直接 echo”。 但是,使用模板也不一定就达不到性能,“我是直接生成 html,大些的项目有必要生成一个”。 模板的坚持使用者们还给出了其它理由: “这个改变不影响模板设计者,内容仍将准确的输出到模板。同样的,哪天美工吃多了想要完全重做界面,也不会影响到程序逻辑。这是 smarty

How do I filter Smarty variable to output only numbers?

橙三吉。 提交于 2019-12-02 03:33:04
问题 Fairly simple question, but I am new to regular expressions and smarty templates, and I can't seem to figure out how to get this working in my smarty template. Basically, I have smarty string that can contain string values like: Home Page Layout 1-1 Home Page Layout 1-2 Home Page Layout 2-1 etc.. I want to extract just the integers from the string so that the output is as followed: 11 12 21 As you can see, I'm removing everything but the integers. I tried doing the following after searching

Smarty Plugin for Eclipse Europa

夙愿已清 提交于 2019-12-02 03:20:31
问题 Are there any good Eclipse plugins for creating smarty templates? I am using Europa with PDT on Ubuntu (though I doubt the OS will make a difference for this). I found SmartyPDT, but it did not seem to install properly and some of the discussions on it seemed to suggest it was for an older version of PDT. 回答1: You can find newer version of this plugin here : http://code.google.com/p/smartypdt/issues/detail?id=31 But I haven't installed it yet with my machine. 回答2: When I last used PHPeclipse

How do I filter Smarty variable to output only numbers?

情到浓时终转凉″ 提交于 2019-12-02 01:51:21
Fairly simple question, but I am new to regular expressions and smarty templates, and I can't seem to figure out how to get this working in my smarty template. Basically, I have smarty string that can contain string values like: Home Page Layout 1-1 Home Page Layout 1-2 Home Page Layout 2-1 etc.. I want to extract just the integers from the string so that the output is as followed: 11 12 21 As you can see, I'm removing everything but the integers. I tried doing the following after searching around, but it doesn't work or output anything. {$SelectHomePageLayout|regex_replace:'[^0-9]+':''}

Variable passed from PHP to Smarty and to Javascript

旧城冷巷雨未停 提交于 2019-12-01 23:13:57
I have an object in php, which is passed to Smarty like $smarty->assign('o',$o) Then I need to access that object and it's properties in javascript. How do you do it, without having any javascript in tpl. i want them all in an external file. If not possible, how to do it? To combine zerkms's and Didozavar's answers, here's a reusable modifier function: <?php function jsify($object, $name = 'foo'){ $json_object = json_encode($object); return "<script type=\"text/javascript\"> var $name = $json_object; </script>"; } $smarty->register_modifier("jsify", "jsify"); $smarty->assign("foo", $foo);

Variable passed from PHP to Smarty and to Javascript

半城伤御伤魂 提交于 2019-12-01 22:54:37
问题 I have an object in php, which is passed to Smarty like $smarty->assign('o',$o) Then I need to access that object and it's properties in javascript. How do you do it, without having any javascript in tpl. i want them all in an external file. If not possible, how to do it? 回答1: To combine zerkms's and Didozavar's answers, here's a reusable modifier function: <?php function jsify($object, $name = 'foo'){ $json_object = json_encode($object); return "<script type=\"text/javascript\"> var $name =

Shouldn't mysql_real_escape_string() leave slashes in Database?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 20:17:13
Im using smarty and mysql_real_escape_string() for user input, and when I insert some code with ' or " , and lookup in phpmyadmin it shows without backslashes. When I get record from DB i doesn't have backslashes also. But when I just pass escaped string without inserting into the db it is backslashed. Shouldn't it add slashes, insert with them and then I would strip them when i would output? Or am I missing something? You're missing it - escaping with backslashes is meant to ensure that queries aren't malformed, e.g. something like this will surely break and possibly risk SQL injections:

盘点2019年PHP高级开发工程师面试题及答案汇总

你。 提交于 2019-12-01 19:50:20
今天小编给大家整理一下关于PHP培训高级面试题及答案汇总,下面我们一起来看一下吧。 1.写出一个能创建多级目录的PHP函数 /** * 创建多级目录 * @param $path string 要创建的目录 * @param $mode int 创建目录的模式,在windows下可忽略 */ function create_dir($path,$mode = 0777) { if (is_dir($path)) { # 如果目录已经存在,则不创建 echo "该目录已经存在"; } else { # 不存在,创建 if (mkdir($path,$mode,true)) { echo "创建目录成功"; } else { echo "创建目录失败"; } } } ?> 2.写出smarty模板的特点? 速度快,编译型,缓存技术,插件机制,强大的表现逻辑 3.打开php.ini中的safe_mode,会影响哪些函数?至少说出6个 safe_mode,php安全模式,它提供一个基本安全的共享环境,在一个有多个用户账户存在的php开发的web服务器上。当安全模式打开的时候,一 些函数将被完全的禁止,而另一些函数的功能将会受到限制, 如:chdir,move_uploaded_file,chgrp,parse_ini_file,chown,rmdir,copy,rename,fopen

PHP filemtime function - “stat failed for”

风格不统一 提交于 2019-12-01 17:10:30
I have a problem with PHP filemtime function. In my webapp I use Smarty template engine with caching option. In my webapp I can do some actions which generate error, but lets focus on only one action. When I click link on page some content is updated - I can click few times and everything is OK but about one request on 10 fails. Following error occurs: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for and the line that causes the problem: return ($_template->getCachedFilepath() && file_exists($_template->getCachedFilepath())) ? filemtime($_template-

Pure PHP/HTML views VS template engines views

♀尐吖头ヾ 提交于 2019-12-01 15:48:04
I would like to know which approach is faster, using the pure PHP in the HTML files or using a template engines like Smarty,Twig, ... What I would particularly like to know is next: which is parsed faster, is the Smarty cache for example faster than using pure PHP? Which of the template engines is the fastest? I'm about to rewrite simple application where speed is on the first place. rodneyrehm "Depends" is the answer to all your questions. What is "faster"? Execution time? Development time? Maintenance? Memory overhead? A mixture of them? A template engine is usually trading in some