- 浏览: 4181169 次
最新评论
Integrating Smarty with the Zend Framework
相关推荐
- Easy PHP Websites with the Zend Framework
Introducing the Zend Framework CHAPTER 6. Talking to the Database with Zend_Db CHAPTER 7. Processing Forms and Sending Email CHAPTER 8. Managing Your User Community CHAPTER 9. Integrating Google ...
- VTK 13 Integrating with the Windowing__ System.pdf
VTK 13 Integrating with the Windowing__ System.pdf VTK 13 Integrating with the Windowing__ System.pdf
- Integrating Python with Leading Computer Forensics Platforms epub
Integrating Python with Leading Computer Forensics Platforms 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
- Integrating SystemC Models with Verilog and SystemVerilog.pdf
Integrating SystemC Models with Verilog and SystemVerilog.pdf
- Integrating.Python.with.Leading.Computer.Forensics.Platforms
Integrating Python with Leading Computer Forensic Platforms takes a definitive look at how and why the integration of Python advances the field of digital forensics. In addition, the book includes ...
- Programming Entity Framework 2nd Edition
This is definitely the book to have by your side if you are programming with the ADO.NET Entity Framework 1.0. The author touches on a ton of subjects that include: Data Binding with Windows Forms ...
- Integrating SharePoint with Excel Outlook Access and Word
Apress - Office and SharePoint 2010 Users Guide - Integrating SharePoint with Excel Outlook Access and Word
- Integrating Python with Leading Computer Forensics Platforms 无水印pdf
Integrating Python with Leading Computer Forensics Platforms 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源...
- Entity Framework Core Cookbook - Second Edition 2016
Make the best of your .NET APIs by integrating with Entity Framework Book Description You will start off by learning how to efficiently use Entity Framework in practical situations. You will gain a ...
- Embedded.Linux.Systems.with.the.Yocto.Project.0133443248
If you’re a developer with working knowledge of Linux, Embedded Linux Systems with the Yocto Project™ will help you make the most of it. An indispensable companion to the official documentation, ...
- Integrating and Extending BIRT 2nd Edition
Part V Working with the Extension Framework Chapter 16 Building the BIRT Project Chapter 17 Extending BIRT Chapter 18 Developing a Report Item Extension Chapter 19 Developing a Report Rendering ...
- Entity.Framework.Core.Cookbook.2nd.Edition
Make the best of your .NET APIs by integrating with Entity Framework Book Description Entity Framework is a highly recommended Object Relation Mapping tool used to build complex systems. In order to ...
- Integrating Scout with FactorySuite 2000 Components
This Tech Note describes how to integrate Wonderware® Scout™ with the following Wonderware® FactorySuite™ 2000 components on Windows NT 4.0: Wonderware® InTouch™, Wonderware® InBatch™, ...
- Entity Framework Core in Action-原版
What's Inside Querying a relational database with LINQ Using EF Core in business logic Integrating EF with existing C# applications Applying domain-driven design to EF Core Getting the best ...
- Cassandra
The rising popularity of Apache Cassandra rests on its ability to handle very ... Get examples for writing clients in Java, Python, and C#, Extend Cassandra by integrating it with the Hadoop framework
- Entity Framework Core in Action
You'l start with a clear breakdown of Entity Framework, long with the mental model behind ORM. Then you'll discover time-saving patterns and best practices for security, performance tuning, and even ...
- Beginning.Object-Oriented.Programming.with.C#
you'll discover how to transform a simple model of an application into a fully-functional C# project, including designing the user interface, implementing the business logic, and integrating with a ...
- Integrating SuccessFactors with SAP.zip
sap press doc 解压密码:abap_developer
- Truffle quick start guide
Also, you will dive into migration, testing and integrating Truffle with the use of popular JavaScript frameworks. Lastly, you will ship your decentralized application and package it into a product. ...
PHPDeveloper.org just pointed out a related article on caching using Smarty. This will fit nicely with what Ralf has written here.
currently I am using the ezcConfiguration and ezcConfigurationIniReader from the ezComponents
http://ez.no/doc/components/view/latest/(file)/introduction_Configuration.html
To integrate the ezComponents within the Zend Framework I put the ezComponents directory in my include_path and use a slightly different __autoload() function:
<pre>
include_once 'Zend.php';
include_once 'Base/src/base.php';
function __autoload($class)
{
if ('ezc' == substr($class, 0, 3))
{
ezcBase::autoload($class);
}
else
{
Zend::loadClass($class);
}
}
</pre>
To use the Configuration component I set it up and store the configuration object in the object store of the Zend Framework.
<pre>
$reader = new ezcConfigurationIniReader();
$reader->init('path/to/your/ini/files', 'settings.ini');
$config = $reader->load();
Zend::register('config', $config);
</pre>
That is basically it.
HTH, Ralf
If you redefined the Smarty Tags to "<?" and "?>" and uses Templates it allows you to see a really clean design in your design editor (there are other ways to do that, but this is quick!!). Templates also make it easy to develop huge interface changes in all your application on the fly without touching your code (the customers like that!!!) and taking advantage of the smarty cache management.
Another thing that helped me was the idea of Tom Anderson of adding a "T" block for Internationalization support. With this you, can even make your design in English and tagged all translatable text with "T" blocks and after use a Smarty-T- block plugin to support your application in different languages. I used in Japanese and I developed my own t block plug in like this:
function smarty_block_t($params, $content, &$this)
{
if (!$content)
return $content;
return i18ngettext(trim($content));
}
The i18ngettext is a function that search into the localization files and returns the content with the translated phrase if it exists. I rewrite the i18ngettext in order to cached the files.
In design time text will look like:
<?t?>Translate me<?/T?>
Bye,
Hermann
For example if you created a Zend_View_Helper_MakeUrl and want to invoke it through a template:
<a href="{makeUrl('index','login')}">Login</a>
I don't think it is possible by using your approach because the helper method are unknown to the smarty object.
In my code is assigned a Zend_View Object that includes all output variables to the smarty object by doing:
$view = new Zend_View();
$view->template = 'index.html';
//add other output variables in the actioncontroller
$smarty = new Smarty();
//smarty cfg stuff
//at the end of the script
$smarty->assign('view', $view);
$smarty->display($view->template);
By doing this, smarty will automatically invoke the Zend_View::__call() method to unknown funktions, and that invokes the helper methods. the disadvantage is that you have to use:
<a href="{$view->makeUrl('index','login')}">Login</a>
which is a little more code, but it works for me.
One more Question: Did anyone manage to make TemplateLite (former SmartyLite) working with ZF?
regards, Marc
thanks for your comments on internationalization. Sounds very good to me. For myself, I haven't come to that part yet, but your approach sounds reasonable to me.
Until now what I did was to assign an array called "translate" to Smarty and to access the translation via {$template.to_be_translate}.
Best Regards,
Ralf
you could easily assign the View object to Smarty as well by doing something like this in the _run() method:
protected function _run($template)
{
$this->_smarty->assign('view', $this);
$this->_smarty->display($template);
}
But I haven't tested this yet, so I might be wrong.
Best Regards,
Ralf
I just wanted to drop a comment to tell you how much I appreciate this tutorial. I was in the process of starting a new project, and wanted to use a more stuctured approach. I was all ready using smarty without the Zend framework.
I knew I wanted to use the framework in my new project, but also wanted to use smarty. Your tutorial was the deciding factor in my changing to the Zend Framework. After spending most of yesterday downloading, and installing Apache I was able to get it working. (After spending a few hours learning how th configure Apache. Oh well, the burden of running your own server.)
Anyway, thanks again.
Troy
However, I have made just 4 methods in my class:
three that you have mentioned (__construct, assign, _run) and also _script() - to avoid redundant Zend_Exception:
/**
* Overrides parent's method.
* @param $name string The base name of the script.
* @return void
*/
protected function _script($name)
{
return $name;
}
The main issue in your code (IMHO) is the following: you are extending the Zend_View_Abstract interface by adding several new methods that are not present in the abstract class. This cannot be considered a problem until one day you decide that Smarty is no good - and you should fall back to using Zend_View instead.
Then you can extend the Zend_View and make Torello_View_Zend class with stub methods, and that will be ok - but I think you should mention this in your article.
"Uncaught exception 'Zend_Exception' with message 'File "Zend/View/Helper/run.php" was not found"
Seems that the file run.php is not part of the Zend Framework.
Any Idea ?
Help please.
What can you say about design of my sites?
<a href="http://eumcci.com/htm/images/artical/data/index.php">sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=1">adult sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=2">sex toy party</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=3">sex toy for man</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=4">homemade sex toy</a>
What can you say about design of my sites?
<a href="http://eumcci.com/htm/images/artical/data/index.php">sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=1">adult sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=2">sex toy party</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=3">sex toy for man</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=4">homemade sex toy</a>
What can you say about design of my sites?
<a href="http://eumcci.com/htm/images/artical/data/index.php">sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=1">adult sex toy</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=2">sex toy party</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=3">sex toy for man</a>
<a href="http://eumcci.com/htm/images/artical/data/?page=4">homemade sex toy</a>
I am currently developing my own framework based on ZF and decided to use TemplateLite as template engine.
In response to octavian82 question, I give you Phlame_View_Tpl integrating TemplateLite with Zend View.
You can view the source here:
http://dev.inetive.pl/phlame/Phlame_View_Tpl.phps
And here is some example.
The template: http://dev.inetive.pl/phlame/test_template.tpl
The example code: http://dev.inetive.pl/phlame/tpl_test.phps
And the result: http://dev.inetive.pl/phlame/tpl_test.php
I would appreciate any comments and ideas.
Good article and start point. Smarty is a powerful template tools. Zend is a powerful MVC framework. Together this is a best solution.
I used it in develop many sites with great success.
Best Regards,
http://www.unixvps.com
<code>
class My_Smarty_View extends Zend_View_Abstract
{
private $_smarty;
public function __construct($config = array()) {
parent::__construct($config);
$this->_smarty = new Smarty();
//i have a config object for my application
$root = Zend::registry('config')->get('root', 'project');
$this->_smarty->template_dir = $root.'application/views/';
$this->_smarty->compile_dir = $root.'tmp/templates_c/';
$this->_smarty->config_dir = $root.'tmp/configs/';
$this->_smarty->cache_dir = $root.'tmp/cache/';
}
public function assign($spec) {
$args = func_get_args();
call_user_func(array('parent', 'assign'), $args);
if (is_string($spec)) {
$arg = func_get_arg(1);
$this->_smarty->assign($spec, $arg);
} elseif (is_array($spec)) {
foreach ($spec as $k=>$v) {
$this->_smarty->assign($k, $v);
}
}
else {
throw new Zend_View_Exception('assign() expects a string or array');
}
}
}
<code>
Regards,
<a href="http://www.mp3smonster.net/">mp3</a>
$view = new SmartyView(array(
'compileDir' => './template_c'
));
//Create a new ViewRenderer helper and assign our newly
//created SmartyView object as the view instance
$viewHelper = new Zend_Controller_Action_Helper_ViewRenderer($view);
$viewHelper->setViewSuffix('tpl');
//Save the helper to the HelperBroker
Zend_Controller_Action_HelperBroker::addHelper($viewHelper);
Best Regards,
http://allmusichit.com
private function _run()
{
$this->_smarty->display($this->_template);
}
I have tried run this, but something is wrong and I don't know what. I have created files ant/SmartyView.php (with first code) and I wrote right after Zend_Controller_Action class yours Ant_Controller_Action (second code). I have changed controller and now it extends Ant_Controller_Action. But how use it now
I have a little view in Zend and I don't have idea how it should works... can you give some example code...
---
<a href=http://review.divx-blog.net/>Review films</a>
I've translated this article into Chinese.
[url]http://www.codebit.cn/pub/html/php_mysql/tutorial/integrating_smarty_with_the_zend_framework/[/url]