32,12 → 32,27 |
protected $_template_vars = array(); |
|
/** |
* Stylesheets to be inserted into the <code>head</code> element |
* |
* @var array |
*/ |
protected $_stylesheets = array(); |
|
/** |
* Scripts to be inserted into the <code>head</code> or |
* <code>body</code> element |
* |
* @var array |
*/ |
protected $_scripts = array(); |
|
/** |
* Creates a new view |
* |
* @param string $template |
* Template resource path |
*/ |
public function __construct($template) |
public function __construct ($template) |
{ |
$this->_template = $template; |
} |
50,7 → 65,7 |
* @param mixed $value |
* Variable value |
*/ |
public function __set($name, $value) |
public function __set ($name, $value) |
{ |
$this->_template_vars[$name] = $value; |
} |
61,7 → 76,7 |
* @param string $name |
* Variable name |
*/ |
public function __get($name) |
public function __get ($name) |
{ |
return $this->_template_vars[$name]; |
} |
75,7 → 90,7 |
* |
* @param mixed $value |
*/ |
public function escape($value) |
public function escape ($value) |
{ |
if (is_array($value)) |
{ |
123,7 → 138,7 |
* @return mixed The assigned value (after possible HTML encoding) |
* @see View::escape() |
*/ |
public function assign($name, $value, $escape = false) |
public function assign ($name, $value, $escape = false) |
{ |
if ($escape) |
{ |
135,6 → 150,54 |
} |
|
/** |
* Adds a CSS resource (stylesheet) to the list of external |
* stylesheets |
* |
* @param string $uri |
* Stylesheet URI |
* @param mixed $key (optional) |
* Array key for the script. May be used later to exclude |
* or include the code for a specific stylesheet. |
*/ |
public function addStylesheet ($uri, $key = null) |
{ |
$stylesheets =& $this->_stylesheets; |
|
if ($key !== null) |
{ |
$stylesheets[$key] = $uri; |
} |
else |
{ |
$stylesheets[] = $uri; |
} |
} |
|
/** |
* Adds an ECMAScript resource (script) to the list of external |
* scripts |
* |
* @param string $uri |
* Script URI |
* @param mixed $key (optional) |
* Array key for the script. May be used later to exclude |
* or include the code for a specific script. |
*/ |
public function addScript ($uri, $key = null) |
{ |
$scripts =& $this->_scripts; |
|
if ($key !== null) |
{ |
$scripts[$key] = $uri; |
} |
else |
{ |
$scripts[] = $uri; |
} |
} |
|
/** |
* Renders the view by including a template |
* |
* @param string $template |
142,7 → 205,7 |
* If not provided, the default template ($template property) will be used. |
* @throws Exception if no template has been defined before |
*/ |
public function render($template = null, $content = null) |
public function render ($template = null, $content = null) |
{ |
if (!is_null($content)) |
{ |
167,9 → 230,67 |
} |
|
/** |
* Returns the code for including all stylesheets, |
* with exclusions. |
* |
* @param array $exclusions (optional, future) |
* The keys of the stylesheets that should be excluded |
* @return string |
*/ |
public function getStylesheets ($exclusions = array()) |
{ |
return ( |
implode(PHP_EOL, array_map(function ($uri) { |
return '<link rel="stylesheet" href="' . $this->escape($uri) . '">'; |
}, array_diff_key($this->_stylesheets, array_flip($exclusions)))) |
. PHP_EOL); |
} |
|
/** |
* Returns the code for including a specific stylesheet |
* |
* @param mixed $key |
* @return string |
*/ |
public function getStylesheet ($key) |
{ |
return '<link rel="stylesheet" href="' |
. $this->escape($this->_stylesheets[$key]) |
. '">' . PHP_EOL; |
} |
|
/** |
* Returns the code for including all stylesheets, |
* with exclusions. |
* |
* @param array $exclusions (optional, future) |
* The keys of the scripts that should be excluded. |
* Usually you would specify those scripts that you |
* want to include with {@link #getScript()}. |
* @return string |
*/ |
public function getScripts ($exclusions = array()) |
{ |
return ( |
implode(PHP_EOL, array_map(function ($uri) { |
return '<script type="text/javascript" src="' |
. $this->escape($uri) |
. '"></script>'; |
}, array_diff_key($this->_scripts, array_flip($exclusions)))) |
. PHP_EOL); |
} |
|
public function getScript ($key) |
{ |
return '<link rel="stylesheet" href="' |
. $this->escape($this->_scripts[$key]) |
. '">' . PHP_EOL; |
} |
|
/** |
* Returns the content for insertion into the template |
*/ |
public function getContent() |
public function getContent () |
{ |
return $this->_content; |
} |
180,7 → 301,7 |
* @param int[optional] $id |
* @see Application::getURL() |
*/ |
public function getURL($controller = null, $action = null, $id = null) |
public function getURL ($controller = null, $action = null, $id = null) |
{ |
return Application::getInstance()->getURL($controller, $action, $id); |
} |