Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 50 → Rev 51

/trunk/View.php
1,5 → 1,7
<?php
 
namespace PointedEars\PHPX;
 
require_once __DIR__ . '/Application.php';
require_once __DIR__ . '/AbstractModel.php';
 
16,7 → 18,7
* @var string
*/
protected $_template = '';
 
/**
* Content that can be inserted in the template
*
23,7 → 25,7
* @var string
*/
protected $_content = '';
 
/**
* Template variables. The variable name serves as item key, the item's value
* is the variable value.
31,7 → 33,7
* @var array
*/
protected $_template_vars = array();
 
/**
* Creates a new view
*
42,7 → 44,7
{
$this->_template = $template;
}
 
/**
* Magic setter method used for defining template variables
*
66,7 → 68,7
{
return $this->_template_vars[$name];
}
 
/**
* Returns <var>$v</var> with occurences of '&' (ampersand), '"' (double quote),
* "'" (single quote), '<' (less than), and '>' (greater than) replaced by their
91,7 → 93,7
$value->$varName = self::escape($value->$varName);
}
}
 
return $value;
}
else
105,11 → 107,11
}
return htmlspecialchars($value, ENT_QUOTES, $encoding);
}
 
return $value;
}
}
 
/**
* Assigns a value to a template variable
*
134,7 → 136,7
$this->$name = $value;
return $value;
}
 
/**
* Renders the view by including a template
*
145,7 → 147,7
*/
public function render($template = null, $content = null)
{
if (!is_null($content))
if (!is_null($content))
{
ob_start();
require_once $content;
152,7 → 154,7
$this->_content = ob_get_contents();
ob_end_clean();
}
 
if (!is_null($template))
{
require $template;
166,7 → 168,7
throw new Exception('No template defined');
}
}
 
/**
* Returns the content for insertion into the template
*/
174,7 → 176,7
{
return $this->_content;
}
 
/**
* @param string[optional] $controller
* @param string[optional] $action