
If a milestone is already done, begin the description with "\[DONE\]", like this:
* Milestone #: \[DONE\] Unit tests ...
{zone-data}
{zone-data:class-list}
* Zend_Layout
* Zend_Layout_Action_Helper_Layout
* Zend_Layout_Controller_Plugin
* Zend_Layout_Exception
* Zend_View_Helper_Layout
* Zend_View_Inflection (Used by both ViewRenderer and Zend_Layout for mapping script names to actual scripts)
{zone-data}
{zone-data:use-cases}
||UC-01||
h4. Bootstrap
{code:php}
// SETUP
$layout = new Zend_Layout(APPLICATION_PATH . 'user/layouts/');
// - or $layout = new Zend_Layout(array('path' => APPLICATION_PATH . 'user/layouts/', 'view' => $view));
// SET DEFAULT LAYOUT - this will set "APPLICATION_PATH/user/layouts/scripts/sub-page.phtml"
// (layouts/scripts) assumes that you are using a view object of type Zend_View.
$layout->setLayout('SubPage');
{code}
h4. Action controller accessing layout
{code:php}
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
// Default Layout
}
public function fileAction() {
// Layout from alternative.phtml
$this->_helper->layout()->setLayout('alternative');
}
public function namedAction()
{
// Layout from bootstrap configured alternative
$this->_helper->layout()->setLayout('alternative');
}
public function jpegAction()
{
$this->_helper->layout()->disableLayout();
}
}
{code}
h4. View accessing layout
{code:php}
<?
// assigning vars to layout:
$this->layout()->myLayoutVar = $this->something
// changing layout script:
$this->layout()->setLayout('foobar');
// disabling layout:
$this->layout()->disableLayout();
?>
{code}
h4. Layout script
{code:php}
<?= $this->docType('xhmt1-transitional') ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?= $this->headTitle() ?></title>
</head>
<body>
<? // 'default' content ?>
<?= $this->layout()->content?>
</body>
</html>
{code}
{zone-data}
{zone-data:skeletons}
h4. Zend_Layout
{code:php}
class Zend_Layout
{
/**
* Set layout script to use
*
* If set after disableLayout() called, implicitly re-enables layout.
*
* @param string $name
* @return Zend_Layout
*/
public function setLayout($name)
{}
/**
* Get current layout script
*
* @return string
*/
public function getLayout()
{}
/**
* Disable layout
*
* @return void
*/
public function disableLayout()
{}
/**
* Set layout script path
*
* @param string $path
* @return Zend_Layout
*/
public function setLayoutPath($path)
{}
/**
* Get current layout script path
*
* @return string
*/
public function getLayoutPath()
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_Layout
*/
public function setView(Zend_View_Interface $view)
{}
/**
* Get current view object
*
* @return Zend_View_Interface
*/
public function getView()
{}
/**
* Set layout variable
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set($key, $value)
{}
/**
* Get layout variable
*
* @param string $key
* @return mixed
*/
public function __get($key)
{}
/**
* Is a layout variable set?
*
* @param string $key
* @return bool
*/
public function __isset($key)
{}
/**
* Unset a layout variable?
*
* @param string $key
* @return void
*/
public function __unset($key)
{}
/**
* Assign one or more layout variables
*
* @param mixed $spec Assoc array or string key; if assoc array, sets each
* key as a layout variable
* @param mixed $value Value if $spec is a key
* @return Zend_Layout
*/
public function assign($spec, $value = null)
{}
/**
* Render layout
*
* Sets internal script path as last path on script path stack, assigns
* layout variables to view, determines layout name using inflector, and
* renders layout view script.
*
* @param mixed $name
* @return mixed
*/
public function render($name = null)
{
}
/**
* Constructor
*
* Accepts either:
* - A string path to layouts
* - An array of options
* - A Zend_Config object with options
*
* Layout script path, either as argument or as key in options, is
* required.
*
* If useMvc flag is false from options, simply sets layout script path.
* Otherwise, also instantiates and registers action helper and controller
* plugin.
*
* @param mixed $options
* @return void
*/
public function __construct($options)
{
}
}
{code}
h4. Zend_Layout_Controller_Plugin
{code:php}
class Zend_Layout_Controller_Plugin extends Zend_Controller_Plugin_Abstract
{
public function __construct(Zend_Layout $layout = null)
{
}
public function setLayout(Zend_Layout $layout)
{
}
public function getLayout()
{
}
/**
* Renders layout
*
* @todo Check for XHR request, check if layout is null, etc.
* @return void
*/
public function dispatchLoopShutdown()
{
$layout = $this->getLayout();
$response = $this->getResponse();
$layout()->assign($response->getBody(true));
$response->setBody($layout->render());
}
}
{code}
h4. Zend_Layout_Action_Helper
{code:php}
class Zend_Layout_Action_Helper extends Zend_Controller_Action_Helper_Abstract
{
public function setLayout(Zend_Layout $layout)
{
}
public function getLayout()
{
}
public function setLayoutName($name)
{
$this->getLayout()->setLayout($name);
}
public function direct($name)
{
return $this->setLayoutName($name);
}
}
{code}
h4. Zend_View_Helper_Layout
{code:php}
/**
* Layout view helper
*
* @package Zend_View
* @subpackage Helpers
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_View_Helper_Layout
{
protected $_front;
public $pluginClass = 'Zend_Layout_Controller_Plugin';
/**
* Constructor
*
* Get front controller instance.
*
* @return void
*/
public function __construct()
{
$this->_front = Zend_Controller_Front::getInstance();
}
/**
* Retrieve Zend_Layout object
*
* @return Zend_Layout|null
*/
public function layout()
{
return $this->getLayout();
}
/**
* Retrieve Zend_Layout instance
*
* @return Zend_Layout
*/
public function getLayout()
{
if (null === $this->_layout) {
if ($this->_front->hasPlugin($this->pluginClass)) {
$this->_layout = $this->_front->getPlugin($this->pluginClass)->getLayout();
}
}
return $this->_layout;
}
/**
* Set layout object
*
* @param Zend_Layout $layout
* @return Zend_View_Helper_Layout
*/
public function setLayout(Zend_Layout $layout)
{
$this->_layout = $layout;
return $this;
}
}
{code}
h4. Zend_View_Inflection
{code:php}
/**
* Zend_View_Inflection
*
* Inflection rules for view scripts.
*
* @package Zend_View
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_View_Inflection
{
/**
* Set base path specification for view object
*
* @param string $path
* @return Zend_View_Inflection
*/
public function setViewBasePathSpec($path)
{}
/**
* Retrieve base path specification
*
* @return string
*/
public function getViewBasePathSpec()
{}
/**
* Set view script path specification
*
* @param string $path
* @return Zend_View_Inflection
*/
public function setViewScriptPathSpec($path)
{}
/**
* Get view script path specification
*
* @return string
*/
public function getViewScriptPathSpec()
{}
/**
* Retrieve view script location based on specification
*
* @param string $action
* @param array $vars
* @return string
*/
public function getViewScript($action, array $vars = array())
{}
/**
* Set view script suffix
*
* @param string $suffix
* @return Zend_View_Inflection
*/
public function setViewSuffix($suffix)
{}
/**
* Retrieve view script suffix
*
* @return string
*/
public function getViewSuffix()
{}
}
{code}