Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-28-2007, 12:07 PM
Junior Member
 
Join Date: Jul 2007
Posts: 1
Default Smarty trouble

While starting creation of admin area module for my project (where I use smarty wrapper as a default view class) I've faced with one problem. My project consists of two ZF modules: default and admin. In both modules there are similar controllers and actions names, e.g. indexController::indexAction(). As as result I have a problem with smarty. It returns the same compiled file for Index actions in Index controller for both modules. Did anyone face with the same trouble?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-28-2007, 04:33 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Quote:
Originally Posted by MasterSID View Post
While starting creation of admin area module for my project (where I use smarty wrapper as a default view class) I've faced with one problem. My project consists of two ZF modules: default and admin. In both modules there are similar controllers and actions names, e.g. indexController::indexAction(). As as result I have a problem with smarty. It returns the same compiled file for Index actions in Index controller for both modules. Did anyone face with the same trouble?
I've tried it and i have the same problem. So here is my problem solution.

PHP Code:
class My_Controller_Action extends Zend_Controller_Action
{
    function 
init()
    {
................
        
$this->view->setCompilePath('../tmp/templates_c/' $this->getRequest()->getModuleName());
................
    } 
my directory structure:
Code:
/application
    /admin
    /default
/library
/public_html
/tmp
    /templates_c
        /admin
        /default
      ......
You must create for each module directory in tmp/template_c.

I'm sorry for my bad english.

Last edited by misaak : 07-28-2007 at 04:45 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-29-2007, 05:42 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

hmm what smarty implementation are you using?
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-29-2007, 12:32 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Quote:
Originally Posted by SpotSec View Post
hmm what smarty implementation are you using?
smarty view

PHP Code:
<?php
require_once 'Smarty/Smarty.class.php';
require_once 
'Zend/View/Abstract.php';


class 
My_View_Smarty extends Zend_View_Abstract
{
    protected 
$_engine;
    
    function 
__construct($params null)
    {
    
parent::__construct($params); 
        
        
$this->_engine = new Smarty();
        
        if (
is_array($params)) {
            foreach (
$params as $key=>$value) {
                
$this->_engine->$key $value;
            }
        }
    }

    public function 
getSmartyEngine()
    {
        return 
$this->_engine;
    }

    public function 
__set($key$val)
    {
        
$this->_engine->assign($key$val);
    }

    public function 
__get($key)
    {
        return 
$this->_engine->get_template_vars($key);
    }

    public function 
__isset($key)
    {
        
$var $this->_engine->get_template_vars($key);
        return !
is_null($var); 
    }

    public function 
__unset($key)
    {
        
$this->_engine->clear_assign($key);
    }

    public function 
assign($spec$value null)
    {
        if (
is_array($spec)) {
               
$this->_engine->assign($spec);
            return 
$this;
        }
    
        
$this->_engine->assign($spec$value);
    return 
$this;
    }

    public function 
clearVars()
    {
        
$this->_engine->clear_all_assign();
    return 
$this;
    }

    public function 
render($name)
    {
        
$this->_file $this->_script($name);
    
$dir  substr($this->_file0strlen($this->_file) - strlen($name));
    
$this->_engine->template_dir $dir;
        
        return 
$this->_engine->fetch($name);
    }
        
    public function 
setPluginPath($dir)
    {
        
$this->_engine->plugins_dir $dir;
    return 
$this;
    }

    public function 
addPluginPath($dir)
    {
        
$this->_engine->plugins_dir[] = $dir;
    return 
$this;
    }

    public function 
setCompilePath($dir)
    {
        
$this->_engine->compile_dir $dir;
    return 
$this;
    }
    
    public function 
setCachePath($dir)
    {
        
$this->_engine->cache_dir $dir;
    return 
$this;
    }
    
    public function 
setCacheLifetime($seconds)
    {
        
$this->_engine->cache_lifetime $seconds;
    return 
$this;
    }
    
    public function 
setBasePath($path$classPrefix 'Zend_View')
    {
    
parent::setBasePath($path$classPrefix);
        
$path        rtrim($path'/');
        
$path        rtrim($path'\\');
        
$path       .= DIRECTORY_SEPARATOR;
        
$classPrefix rtrim($classPrefix'_') . '_';
        
$this->setScriptPath($path 'templates');
    
$this->setPluginPath($path 'plugins');
        
    return 
$this;
    }
    
    public function 
addBasePath($path$classPrefix 'Zend_View')
    {
    
parent::addBasePath($path$classPrefix);
        
$path        rtrim($path'/');
        
$path        rtrim($path'\\');
        
$path       .= DIRECTORY_SEPARATOR;
        
$classPrefix rtrim($classPrefix'_') . '_';
        
$this->addScriptPath($path 'templates');
    
$this->addPluginPath($path 'plugins');

        return 
$this;
    }
    
    function 
_run()
    {            
    }
}
and in bootstrap
PHP Code:
$view = new My_View_Smarty($config->smarty->toArray());
$viewRenderer Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view)
                      ->
setViewSuffix('tpl'); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:57 AM.