Browse Source

Added FormViewHelper @method form() to PHPView

master
Anton Terekhov 12 years ago
parent
commit
e5a0df37fc
  1. 43
      view/PHPView.php

43
view/PHPView.php

@ -5,8 +5,6 @@
* @package Majestic * @package Majestic
* @subpackage View * @subpackage View
* @since 2010-02-25 * @since 2010-02-25
* @version SVN: $Id$
* @filesource $URL$
*/ */
/** /**
@ -15,17 +13,22 @@
* @method HeadViewHelper head() head(string $string = false) Append another string to HEAD section of Layout * @method HeadViewHelper head() head(string $string = false) Append another string to HEAD section of Layout
* @method MsgViewHelper msg() msg(string $msg = null, string $type = null) Set a message to display for user in Layout * @method MsgViewHelper msg() msg(string $msg = null, string $type = null) Set a message to display for user in Layout
* @method TitleViewHelper title() title(string $string = false) Append another section for TITLE of Layout * @method TitleViewHelper title() title(string $string = false) Append another section for TITLE of Layout
* @method FormViewHelper form() form(string $form = null) Get form values from session
* *
*/ */
class PHPView implements iView class PHPView implements iView
{ {
protected $path = '';
protected $path = '';
protected $variables = array(); protected $variables = array();
protected $helpers = array();
protected $helpers = array();
protected $extension = '.phtml'; protected $extension = '.phtml';
protected $template = '';
protected $template = '';
public function __construct($config) public function __construct($config)
{ {
if (!isset($config['path'])) { if (!isset($config['path'])) {
@ -33,17 +36,17 @@ class PHPView implements iView
} }
$this->setPath($config['path']); $this->setPath($config['path']);
} }
public function getPath() public function getPath()
{ {
return $this->path; return $this->path;
} }
public function setPath($path) public function setPath($path)
{ {
$this->path = $path; $this->path = $path;
} }
/** /**
* @param Action $object * @param Action $object
*/ */
@ -53,7 +56,7 @@ class PHPView implements iView
$this->assign($name, $value); $this->assign($name, $value);
} }
} }
/** /**
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
@ -62,7 +65,7 @@ class PHPView implements iView
{ {
$this->variables[$name] = $value; $this->variables[$name] = $value;
} }
/** /**
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
@ -75,7 +78,7 @@ class PHPView implements iView
$this->variables[$name] = $value; $this->variables[$name] = $value;
} }
} }
/** /**
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
@ -88,7 +91,7 @@ class PHPView implements iView
$this->variables[$name] = $value; $this->variables[$name] = $value;
} }
} }
public function fetch($template) public function fetch($template)
{ {
$this->template = $this->getTemplatePath($template); $this->template = $this->getTemplatePath($template);
@ -97,20 +100,20 @@ class PHPView implements iView
ob_start(); ob_start();
if (!is_readable($this->template)) { if (!is_readable($this->template)) {
ob_clean(); ob_clean();
throw new GeneralException('Template "' . $this->template .'" not found.');
throw new GeneralException('Template "' . $this->template . '" not found.');
} }
include($this->template); include($this->template);
return ob_get_clean(); return ob_get_clean();
} }
public function escape($var) public function escape($var)
{ {
return htmlentities($var, ENT_QUOTES, 'UTF-8'); return htmlentities($var, ENT_QUOTES, 'UTF-8');
} }
/** /**
* Helpers call * Helpers call
*
*
* @param mixed $name * @param mixed $name
* @param mixed $args * @param mixed $args
* @return ViewHelper * @return ViewHelper
@ -120,7 +123,7 @@ class PHPView implements iView
$helper = $this->getHelper($name); $helper = $this->getHelper($name);
return call_user_func_array(array($helper, $name), $args); return call_user_func_array(array($helper, $name), $args);
} }
protected function getHelper($name) protected function getHelper($name)
{ {
if (!isset($this->helpers[$name])) { if (!isset($this->helpers[$name])) {
@ -132,7 +135,7 @@ class PHPView implements iView
} }
return $this->helpers[$name]; return $this->helpers[$name];
} }
protected function getTemplatePath($template) protected function getTemplatePath($template)
{ {
return $this->path . $template . $this->extension; return $this->path . $template . $this->extension;

Loading…
Cancel
Save