/**
* Return the template engine object
*
* @return Template_
*/
public function getEngine()
{
return $this->Template_;
}
/**
* Set the path to the templates
*
* @param string $path The directory to set as the path.
* @return void
*/
public function setScriptPath($path)
{
if (is_readable($path)) {
$this->Template_->template_dir = $path;
return;
}
throw new Exception($this->Template_->template_dir);
}
/**
* Retrieve the current template directory
*
* @return string
*/
public function getScriptPaths()
{
return array($this->Template_->template_dir);
}
/**
* Alias for setScriptPath
*
* @param string $path
* @param string $prefix Unused
* @return void
*/
public function setBasePath($path, $prefix = ‘Zend_View‘)
{
return $this->setScriptPath($path);
}
/**
* Alias for setScriptPath
*
* @param string $path
* @param string $prefix Unused
* @return void
*/
public function addBasePath($path, $prefix = ‘Zend_View‘)
{
return $this->setScriptPath($path);
}
/**
* Assign a variable to the template
*
* @param string $key The variable name.
* @param mixed $val The variable value.
* @return void
*/
public function __set($key, $val)
{
$this->Template_->assign($key, $val);
}
/**
* Allows testing with empty() and isset() to work
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return (null !== $this->Template_->getTemplate_vars($key));
}
/**
* Allows unset() on object properties to work
*
* @param string $key
* @return void
*/
public function __unset($key)
{
$this->Template_->clear_assign($key);
}
/**
* Assign variables to the template
*
* Allows setting a specific key to the specified value, OR passing
* an array of key => value pairs to set en masse.
*
* @see __set()
* @param string|array $spec The assignment strategy to use (key or
* array of key => value pairs)
* @param mixed $value (Optional) If assigning a named variable,
* use this as the value.
* @return void
*/
public function assign($spec, $value = null)
{
if (is_array($spec)) {
$this->Template_->assign($spec);
return;
}
$this->Template_->assign($spec, $value);
}
/**
* Clear all assigned variables
*
* Clears all variables assigned to Zend_View either via
* {@link assign()} or property overloading
* ({@link __get()}/{@link __set()}).
*
* @return void
*/
public function clearVars()
{
$this->Template_->clear_all_assign();
}
/**
* Processes a template and returns the output.
*
* @param string $name The template to process.
* @return string The output.
*/
public function render($name)
{
return $this->Template_->fetch($name);
}
}
?>
-----------------------------------------------------------------------------------------------------
이 소스는 ZendFramework 레퍼런스에서 제공하는 smarty 쓰는 방법중에 나와있는 소스를
smarty -> template_ 라는 글자로만 고쳤다.
그래도 동작이 된다
버그가 있는지는 차근차근 써보면서 찾아보기록 하고 일단 잘되니 패스
----------------------------------------------------------------------------------------------------
set_include_path로
/library/Template_.2.2.4
경로를 세팅한다.
php.ini에 등록해도 되나 귀차니즘으로 header.php 같은곳에 넣어 쓰세요
----------------------------------------------------------------------------------------------------
Bootstrap.php에 다음 함수를 추가한다.
function _initTemplate()
{
//xtac.net 에서 제공하는 Template_ 클래스 생성
//경로는 환경 클래스(Zend_Config) 에서 등록하여 로드하는게 편하다
$view = new Zend_View_TemplateUnderbar("템플릿경로");
$view->Template_->compile_dir = "컴파일경로";
$view->Template_->prefilter = "adjustPath";
//Zend_View 에서 Rander를 담당하는 인스턴스를 얻어와서 템플릿 언더바와 연결한다.
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(‘viewRenderer‘);
$viewRenderer->setView($view)
->setViewBasePathSpec($view->Template_->template_dir)
->setViewScriptPathSpec(‘index‘)
->setViewScriptPathNoControllerSpec(‘:action.:suffix‘)
->setViewSuffix(‘tpl‘);
//setViewScriptPathSpec(‘index‘) 의 index는 위에 $view->Template_->define 에서 선언된 index 파일을 print_ 해준다.
}
마지막으로
Action 에서
템플릿 언더바를 가져다 쓰기만 하면 된다.
class IndexController extends Zend_Controller_Action
public function indexAction()
{
$subtitle = "TEST";
$_tpl = Zend_Registry::get("Template_");
$_tpl->define(array(‘content‘=>‘bbs/index.tpl‘));
$_tpl->assign(array(‘subtitle‘=>$subtitle));
}
}
----------------------------------------------------------------------------------------------------
잘되시나요?
관리자
미바니님 안녕하세요..
올려주신 소스에서 __isset, __unset, clearVars 메소드만 아래와 같이 고쳐주시면 될 것 같습니다.
public function __isset($key)
{
return isset($this->Template_->var_[''][$key]);
}
public function __unset($key)
{
unset($this->Template_->var_[''][$key]);
}
public function clearVars()
{
$this->Template_->var_['']=array();
}