GGshow reloaded GGshow reloaded

July 4, 2012

Zend Framework – View Helper – Placeholder

Example usage for place holders:

  • doctype()
  • headTitle()
  • headMeta()
  • headLink()
  • headStyle()
  • headScript()
  • inlineScript()

DOCTYPE

$view->doctype('HTML5');

Title

$view->headTitle('Site Title');
$view->headTitle('Site Title')
	->setSeparator(' :: ');

Meta

$view->headMeta()->appendName('keywords', 'page, keywords')
	->appendName('description', 'page description')
	->appendName('author', 'author name');

Refresh

$view->headMeta()->appendHttpEquiv('Refresh','30');

Redirect

$view->headMeta()->appendHttpEquiv('Refresh','0;url=http://www.ggshow.com');

Disable client side cache

$view->headMeta()->appendHttpEquiv('expires','-1')
	->appendHttpEquiv('pragma', 'no-cache')
	->appendHttpEquiv('Cache-Control', 'no-cache');

Setting content type and character set

$view->headMeta()->setCharset('utf-8');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
	->appendHttpEquiv('Content-Language', 'en-US');

Favicon with headLink

$view->headLink(array('rel' => 'favicon', 'href' => 'favicon.ico'),'PREPEND');
$view->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => 'favicon.ico'),'PREPEND');

CSS with headLink

$view->headLink()->appendStylesheet('style.css');

// appendStylesheet, prependStylesheet, setStylesheet, offsetStylesheet, appendAlternative, prependAlternative, setAlternative, offsetAlternative

CSS with headStyle

$view->headStyle->captureStart();
?>
body { margin: 0; }
<?php
$view->headStyle->captureEnd();

JavaScript

$view->headScript()->appendFile(“script.js”);
$view->headScript()->prependFile(“script.js”);
$view->inlineScript()->appendFile(“script.js”);
$this->headScript()->appendFile('script.js', 'text/javascript', array('conditional' => 'lt IE 7') );

Example output (within layout/view)

echo $this->headTitle();
echo $this->headLink();
echo $this->headMeta();
echo htmlentities($view->headMeta()->setPostfix("n"));

Example layout with placeholders

<?php echo $this->doctype() ?>
<html>
	<head>
		<?php echo $this->headTitle() ?>
		<?php echo $this->headScript() ?>
		<?php echo $this->headStyle() ?>
	</head>
	<body>
		<?php echo $this->layout()->content; ?>
		<?php echo $this->inlineScript() ?>
	</body>
</html>

Zend Framework – View Helper – Layout

To get layout object

  • within view script
    $layout = $this->layout()
  • within action controller
    $layout = $this->_helper->layout()
    $layout = $this->_helper->getHelper(‘Layout’)->getLayoutInstance()
  • within bootstrap
    $layout = $bootstrap->getResource(‘Layout’);
  • elsewhere
    $layout = Zend_Layout::getMvcInstance();

To assign variable to layout object

$layout->var = ‘value’;
$layout->assign(‘var’, ‘value’);

To enable or disable layout

$layout->enableLayout();
$layout->disableLayout();

To enable or disable layout using CLI

zf enable layout
zf disable layout
Filed under: PHP,Web,Zend Framework — Tags: , , , , , — GG @ 2:27 pm

© 2024 GGSHOW | Powered by WordPress