Home » support » General discussion » Smarty view
| Re: Smarty view [message #14786 is a reply to message #14744 ] |
Fri, 27 October 2006 13:47   |
|
I am in a rush at work at the moment and doing lots of overtime.
I'll take a look as soon as things calm down here.
Christian Roy
Zend Certified PHP5 Programmer
* Nothing is impossible, the impossible just takes longer! *
|
|
| | | | | |
| Re: Smarty view [message #20233 is a reply to message #20190 ] |
Tue, 23 January 2007 11:04   |
chiba Messages: 3 Registered: January 2007 |
Junior Member |
|
|
|
oops. I submitted duplicate message.
[Updated on: Tue, 23 January 2007 11:14]
|
|
| | |
| Re: Smarty view [message #20370 is a reply to message #20360 ] |
Thu, 25 January 2007 04:18   |
chiba Messages: 3 Registered: January 2007 |
Junior Member |
|
|
Hi Geg.
I'm Japanese and cannot use English so well.
| _GeG_ wrote on Wed, 24 January 2007 20:58 | @chiba: thanks for the patch, I have included it in version 0.1.3
@Kyle: I have included the config vars in the documentation, including the path to the smarty file.
BTW which helpers are you missing?
|
maybe, that is appearing exeptions when symfony's SF_ENVIRONMENT set to "dev".
Unable to load "SmartyHelperHelper.php" helper ....
this exeption occuring in loadHelper().
try {
sfLoader::loadHelpers(array($helperName, 'Smarty' . $helperName));
}
Using "set_error_handler" when symfony's SF_ENVIRONMENT set to "dev".
Then although using try ,sfTestBrowserErrorHandler catch the error and write log.
This problem doesn't really matter.
But if somebody feel uneasy then use this patch.
--- sfSmartyViewPlugin-0.1.2\lib\sfSmartyView.class.php.orig Thu Jan 25 11:31:27 2007
+++ sfSmartyViewPlugin-0.1.2\lib\sfSmartyView.class.php Thu Jan 25 12:09:51 2007
@@ -172,7 +172,12 @@
}
include (self::$cache->getFile($helperName, self::CACHENAMESPACE));
try {
- sfLoader::loadHelpers(array($helperName, 'Smarty' . $helperName));
+ if (self::isExistSmartyHelper($helperName)) {
+ sfLoader::loadHelpers(array($helperName, 'Smarty' . $helperName));
+ }
+ else {
+ sfLoader::loadHelpers(array($helperName));
+ }
}
catch (sfViewException $e) {
if (!strpos($e->getMessage(), 'Smarty' . $helperName)) {
@@ -182,6 +187,21 @@
self::$loadedHelpers[$helperName] = true;
}
+ /*
+ * @param string $helperName
+ * @return boolean
+ */
+ private function isExistSmartyHelper($helperName) {
+ if ($pluginHelperDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/helper') ) {
+ foreach ($pluginHelperDirs as $pluginHelperDir) {
+ if (is_readable($pluginHelperDir . '/Smarty' . $helperName . 'Helper.php')) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/**
* sfSmartyView::parseFile()
*
Maybe best way(for performance) is make "SmartyHelperClass array"
and using array_key_exists in isExistSmartyHelper.
[Updated on: Thu, 25 January 2007 04:53]
|
|
| | |
| Re: Smarty view [message #20488 is a reply to message #574 ] |
Sun, 28 January 2007 23:53   |
Kyle Messages: 7 Registered: January 2007 |
Junior Member |
|
|
@ GeG / chiba
Yes, I found some exceptions in my log file when symfony tried to load the standard helpers but didn't found the smarty helpers like SmartyHelperHelper.php and SmartyUrlHelper.php etc. I think its good practice to load the "normal" symfony helpers if there is no smarty helper available (like chibas patch does), but finally we should cover all helper functions with smarty helpers. Helper functions and files which are not coverd with smarty helpers will be accessible through {php}-tags only (or am I wrong?).
@al_n
That may be a good solution for you . But you'll have a greater effort if you're adding or changing variables which requires you to change at least 2 documents. The symfony helper functions will be another problem for your approach, I think. If you want to access them, you've to use {php}-Tags (or do you have another solution?). But that won't work for me for example. I want to have a strict division between layout and business logic with minimum maintenance effort.
@thread
I found another "problem": Deleting symfonys cache directory causes an exception when SmartyView tries to create it's cache and compile directory. I don't know if *nix systems allow to create two directories "/Smarty/compile" at once, but my Windows won't. I made a patch:
Index: sfSmartyView.class.php
===================================================================
--- sfSmartyViewPlugin-0.1.2\lib\sfSmartyView.class.php.orig Sun Jan 28 23:40:12 2007
+++ sfSmartyViewPlugin-0.1.2\lib\sfSmartyView.class.php Sun Jan 28 23:44:27 2007
@@ -61,17 +61,29 @@
self::$templateSecurity = sfConfig::get('app_sfSmartyView_template_security', false);
self::$smarty->security = self::$templateSecurity;
self::$log = sfConfig::get('sf_logging_enabled')? $this->getContext()->getLogger() : false;
+
+ // creating smarty subdir if not exists
+ if (!file_exists($smartyDirs)) {
+ if (!mkdir($smartyDirs, 0777, true)) {
+ throw new sfCacheException('Unable to create cache directory "' . $smartyDirs . '"');
+ }
+ if (self::$log) self::$log->info('{sfSmartyView} creating smarty cache directory: ' . $smartyDirs);
+ }
+
+ // creating compile dir
if (!file_exists(self::$smarty->compile_dir)) {
if (!mkdir(self::$smarty->compile_dir, 0777, true)) {
throw new sfCacheException('Unable to create cache directory "' . self::$smarty->compile_dir . '"');
}
if (self::$log) self::$log->info('{sfSmartyView} creating compile directory: ' . self::$smarty->compile_dir);
}
+
+ // creating cache dir
if (!file_exists(self::$smarty->cache_dir)) {
if (!mkdir(self::$smarty->cache_dir, 0777, true)) {
throw new sfCacheException('Unable to create cache directory "' . self::$smarty->cache_dir . '"');
}
- if (self::$log) self::$log->info('{sfSmartyView} creating compile directory: ' . self::$smarty->cache_dir);
+ if (self::$log) self::$log->info('{sfSmartyView} creating cache directory: ' . self::$smarty->cache_dir);
}
self::$smarty->register_compiler_function('use', array($this, 'smartyCompilerfunctionUse'));
self::$smarty->register_postfilter(array('sfSmartyView', 'smartyPostFilter'));
Kyle
[Updated on: Sun, 28 January 2007 23:54]
|
|
| |
| Re: Smarty view [message #20649 is a reply to message #574 ] |
Wed, 31 January 2007 11:35   |
tohenk Messages: 5 Registered: January 2007 Location: Indonesia |
Junior Member |
|
|
Hi all,
I have a look at Smarty Plugin and there is still no support for partial view using Smarty.
I have rewrite the plugin to support this partial. Unfortunately, symfony doesn't have any configuration to support another partial view. So PartialHelper.php also must be modified to accept configuration, say it 'partial_view_class'.
To use Smarty Partial view define (in module.yml):
all:
...
view_class: sfSmarty
partial_view_class: sfSmartyPartial
...
tohenk.
[Updated on: Wed, 28 February 2007 16:53]
|
|
|
| Re: Smarty view [message #20726 is a reply to message #20649 ] |
Thu, 01 February 2007 12:34   |
tohenk Messages: 5 Registered: January 2007 Location: Indonesia |
Junior Member |
|
|
Hi again.
I have attached the other change for SmartyView plugin.
sfSmartyUtil now become static.
Regard.
|
|
| | | |
| Re: Smarty view [message #22677 is a reply to message #22590 ] |
Wed, 28 February 2007 16:49   |
tohenk Messages: 5 Registered: January 2007 Location: Indonesia |
Junior Member |
|
|
Hi johnny,
It seems, you've used modified sfSmartyPlugin.
Try to patch sfSmartyUtils.class.php with this patch.
--- C:\Temp\sfSmartyUtils.class.php.new Mon Feb 12 14:13:39 2007
+++ C:\Temp\sfSmartyUtils.class.php Thu Feb 01 14:52:24 2007
@@ -372,7 +372,6 @@
throw new Exception('sfSmartyUtils: Cannot compile template. Use: {use helper="helpername"}');
}
self::loadHelper($matches[1]);
- self::registerSmartyFunctions($smarty);
return '';
}
Regards.
tohenk
[Updated on: Wed, 28 February 2007 16:59]
|
|
| | | | | | | | |
| Re: Smarty view [message #29699 is a reply to message #574 ] |
Tue, 19 June 2007 05:02   |
port Messages: 408 Registered: February 2007 Location: Dayton, Ohio, USA |
Faithful Member |
|
|
Dear Friends:
I must say that the discussion and team work (which has been going nearly non-stop for two years between people from different places around the world) is a testament, not only to the php / symfony community, but to the internet and how it is flattening the world out and making it a whole lot smaller.
I'm amazed--
BTW--I came to the thread because I'm going to create a plugin for haml and was gleaning any pointer I could from the discussion.
Port
"What if I stumble, what if I fall?
What if I lose my step and I make fools of us all?
Will the love continue when my walk becomes a crawl?
What if I stumble, and what if I fall?" -- DC Talk
|
|
| |
| Re: Smarty view [message #39570 is a reply to message #574 ] |
Thu, 15 November 2007 14:51   |
lexor Messages: 3 Registered: November 2007 Location: Moldova, Chisinau |
Junior Member |
|
|
Is it possible to use automatic admin interface (based on generator.yml) with this plugin? All works nice for common templates and CRUD, but not for this. I get an exception
sfRenderException:
The template "/listSuccess.tpl" does not exist in:
stack trace
...
Hope for your help, thanks!
Imagination is more important than knowledge (Albert Einstein)
|
|
| | | |
| Re: Smarty view [message #42644 is a reply to message #574 ] |
Thu, 03 January 2008 05:18   |
jing Messages: 1 Registered: January 2008 |
Junior Member |
|
|
Hi,
Thank you for SmartyViewPlugin.
(I'm not good at English so please forgive my poor grammar and spelling mistakes.)
I'm trying to migrate my project to symfony with smarty.
There's a lot of code in my templates like this:
{include file="head.tpl"}
{include file="left.tpl"}
{include file="right.tpl"}
{include file="foot.tpl"}
Now I find that the Instance of Smarty Class in SmartyView can parse indexSuccess.tpl and layout.tpl well but failed to include
other templates.
I'v got default^%%06^060^060EF7CE%%layout.tpl.php after Smarty compiled layout.tpl.
I can see a line like this:
$this->_smarty_include(array('smarty_include_tpl_file' => "left.tpl", 'smarty_include_vars' => array()));
while run the page it shows
Warning: Smarty error: unable to read resource: "left.tpl" in path\apps\frontend\lib\Smarty\Smarty.class.php on line 1104
So I added a line in sfSmartyView.class.php
self::$smarty->template_dir = sfConfig::get('sf_app_template_dir', 'templates');
Then it works.
[Updated on: Thu, 03 January 2008 06:33]
|
|
| |
| Re: Smarty view [message #45794 is a reply to message #20414 ] |
Tue, 19 February 2008 09:19   |
eaglebvro Messages: 1 Registered: February 2008 |
Junior Member |
|
|
|
Where should I put your class? In %SF_LIB_DIR%?
|
|
|
| Re: Smarty view [message #46939 is a reply to message #574 ] |
Mon, 03 March 2008 14:27   |
ahmedshaikhm Messages: 7 Registered: May 2007 |
Junior Member |
|
|
I have got Symfony version 1.0.9, Smarty 2.6.19 And PHP 5.2.3 on Windows XP Professional with Apache 2.2.
apps/frontend/config/module.yml
all:
view_class: sfSmarty
apps/frontend/config/app.yml
all:
sfSmartyView:
class_path: %sf_symfony_lib_dir%/vendor/smarty/libs/
template_extension: .tpl
indexSuccess.tpl and layout.tpl are same as sample that is {SYMFONYDIR}plugins\sfSmartyViewPlugin\templates
Action File
public function executeIndex()
{
}
The error is weird. Any clue
Notice: Undefined property: sfSmartyView::$attribute_holder in {HIDDEN}\plugins\sfSmartyViewPlugin\lib\sfSmartyView.class.p hp on line 114
Fatal error: Call to a member function getAll() on a non-object in {HIDDEN}\plugins\sfSmartyViewPlugin\lib\sfSmartyView.class.p hp on line 114
log says:
Mar 03 18:30:08 symfony [info] {sfContext} initialization
Mar 03 18:30:09 symfony [info] {sfController} initialization
Mar 03 18:30:09 symfony [info] {sfRouting} match route [default] "/:module/:action/*"
Mar 03 18:30:09 symfony [info] {sfRequest} request parameters array ( 'module' => 'list', 'action' => 'test',)
Mar 03 18:30:09 symfony [info] {sfController} dispatch request
Mar 03 18:30:09 symfony [info] {sfFilter} executing filter "sfRenderingFilter"
Mar 03 18:30:09 symfony [info] {sfFilter} executing filter "sfCommonFilter"
Mar 03 18:30:09 symfony [info] {sfFilter} executing filter "sfFlashFilter"
Mar 03 18:30:09 symfony [info] {sfFilter} executing filter "sfExecutionFilter"
Mar 03 18:30:09 symfony [info] {sfAction} call "listActions->executeTest()"
Mar 03 18:30:09 symfony [info] {sfView} initialize view for "list/test"
Mar 03 18:30:09 symfony [info] {sfSmartyView} is used for rendering
Mar 03 18:30:09 symfony [info] {sfSmartyView} renderFile {HIDDEN}\apps\frontend\modules/list/templates/testSuccess.tpl
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyHelperHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyUrlHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyAssetHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyPartialHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyCacheHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Mar 03 18:30:09 symfony [err] {sfViewException} Unable to load "SmartyFormHelper.php" helper in: {HIDDEN}\apps\frontend\lib/helper, {HIDDEN}\lib/helper, {HIDDEN}\plugins/sfSmartyViewPlugin/lib/helper, {HIDDEN}\config/../lib/symfony/helper, {HIDDEN}\lib, {HIDDEN}, {HIDDEN}\apps\frontend\lib, {HIDDEN}\config/../lib/symfony\vendor, ., E:\apache2triad\php\pear
Thanks in advance.
-Ahmed,
[Updated on: Mon, 03 March 2008 14:33]
|
|
| | |
Goto Forum:
|