Zend Framework 1.0.3 is released!!
Yahoooooooooooooooooooooooooooooooooooooo!!
Zend Framework 1.0.3 is released today! :p
And so happy to forget how fatty I am!!
(weight I don't kg BMI care%)
Labels: Zend Framework
[phase]
1. A pig which can make your dreams come true.
2. A company's name which the author will make in the future.
3. A diary of a guy who wants to lose weight.
Yahoooooooooooooooooooooooooooooooooooooo!!
Labels: Zend Framework
As you guys know "Smarty" is pretty famous template engine.
php5 -> /usr/local/php525/bin/php
phpize5 -> /usr/local/php525/bin/phpize.
# cd /usr/local/src
# wget http://simplate.aimy.jp/archive/simplate-0.3.7.tar.gz
# tar zxvf simplate-0.3.7.tar.gz
# cd simplate-0.3.7
# phpize5
# ./configure \
--enable-simplate \
--with-php-config=/usr/local/php525/bin/php-config \
--prefix=/usr/local/php525 \
# make
# make install
Installing shared extensions: /usr/local/php525/lib/php/extensions/no-debug-non-zts-20060613/
# vim /usr/local/php525/lib/php.ini
extension=simplate.so
php5 -i | grep simplate
simplatesimplate support => enabled
<?php
require_once 'Zend/View/Interface.php';
class Hoge_View_Simplate implements Zend_View_Interface
{
/**
* Simplate object
* @var Simplate
*/
protected $_simplate;
/**
* constructor
*
* @param string $tmplPath
* @param array $extraParams
* @return void
*/
public function __construct($tmplPath = null, $extraParams = array())
{
$this->_simplate = new Simplate;
if (null !== $tmplPath) {
$this->setScriptPath($tmplPath);
}
foreach ($extraParams as $key => $value) {
$this->_simplate->$key = $value;
}
}
/**
* Return template enginge object.
*
* @return Simplate
*/
public function getEngine()
{
return $this->_simplate;
}
/**
* Set template's path
*
* @param strimg $path Directory path
* @return void
public function setScriptPath($path)
{
if (is_readable($path)) {
$this->_simplate->template_dir = $path;
return;
}
throw new Exception("You specified unrecognized path '{$path}'");
}
/**
* Get current template path.
* @return string
*/
public function getScriptPaths()
{
return $this->_simplate->template_dir;
}
/**
* Alias of setScript path.
*
* @param string $path
* @param string $prefix Unused
* @return void
*/
public function setBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}
/**
* Alias of setScript path.
*
* @param string $path
* @param string $prefix unused
*
* @return void
*/
public function addBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}
/**
* Set valiables to template.
*
* @param string $key valiable name
* @param mixed $val valiable value
* @return void
*/
public function __set($key, $value)
{
$this->_simplate->assign($key, $value);
}
/**
* Get value.
*
* @param string $key valiable name
* @return mixed valiable value
*/
public function __get($key)
{
return $this->_simplate->_tpl_vars[$key];
}
/**
* Enable test for empty() isset().
*
* @param string $key
* @return boolen
*/
public function __isset($key)
{
return isset($this->_simplate->_tpl_vars[$key]);
}
/**
* Enable unset to object valiable.
* @return void
*/
public function __unset($key)
{
unset($this->_simplate->_tpl_vars[$key]);
}
/**
* Set valiable to template.
* set value to specific key.
* set at once by key => value array.
*
* @see __set()
* @param string|array $spec type of settin value (key or key => value array)
* @param mixed $value (optionale) specify the name of key. set here.
* @return void
*/
public function assign($spec, $value = null)
{
if (is_array($spec)) {
foreach($spec as $key => $value) {
$this->_simplate->assign($key, $value);
}
return;
}
$this->_simplate->assign($spec, $value);
}
/**
* Clear all valiables.
* Clear all valiables sat to Zend_View by {@link assign()} or {@link __get()}/{@link __set()}.
*
* @return void
*/
public function clearVars()
{
$this->_simplate->_tpl_vars = null;
}
/**
* Dispatch template and return result.
*
* @param string $name template name
* @return string result
*/
public function render($name)
{
return $this->_simplate->fetch($name);
}
}
function simplateAction()
{
$this->_helper->viewRenderer->setNoRender();
require_once 'Hoge/View/Simplate.php';
$tplPath = dirname(dirname(__FILE__)) . '/views/scripts/hoge/';
$params = array(
'compile_dir' => dirname(dirname(__FILE__)) . '/views/templates_c',
'left_delimiter' => '{',
'right_delimiter' => '}',
);
$view = new Hoge_View_Simplate($tplPath, $params);
foreach(range(0, 20000) as $i) {
$vars[$i] = "Hello World $i";
}
$view->vars = $vars;
echo $view->render('simplate.tpl');
}
<html>
<head></head>
<body>
{foreach key=key item=item from=$vars}
{$key} : {$item} <br />
{/foreach}
</body>
</html>
function preDispatch()
{
$this->startTime = microtime(true);
}
function postDispatch()
{
echo (microtime(true) - $this->startTime);
}
function smartyAction()
{
$this->_helper->viewRenderer->setNoRender();
require_once 'Hoge/View/Smarty.php';
$tplPath = dirname(dirname(__FILE__)) . '/views/scripts/hoge/';
$params = array(
'compile_dir' => dirname(dirname(__FILE__)) . '/views/templates_c',
);
$view = new Hoge_View_Smarty($tplPath, $params);
foreach(range(0, 20000) as $i) {
$vars[$i] = "Hello World $i";
}
$view->vars = $vars;
echo $view->render('smarty.tpl');
}
Simplate: 0.137821912766
Smarty : 0.153032064438
Labels: Zend Framework