Linto
Linto

Reputation: 1282

Layout content is not getting+ Zend

I implemented a Zend project

And its working fine

Now i tried to implement a layout,

Step 1

for that i created a 'layout.phtml' in the folder 'application/layouts'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->headTitle(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>
<?php $this->layout()->content ;?>
</body>
</html>

step2

Modified the application.ini and added the following line

resources.layout.layoutpath = APPLICATION_PATH "/layouts" under [production]

Step3

Modified the Bootstrap.php, and added the function '_initViewHelpers()'

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{

    function _initAutoload()
    {
        $moduleLoader = new Zend_Application_Module_AutoLoader(
            array('namespace'=>'','basePath'=>APPLICATION_PATH)
        );
        return $moduleLoader;
    }

    function _initViewHelpers()
    {
        $this->bootstrap('layout');
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $view->doctype('XHTML1_STRICT');
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
        $view->headTitle()->setSeparator(' - ');
        $view->headTitle('Zend Framework Tutorial');
    }
}
?>

Step4

I took the url in the browser http://localhost/zf_tutorial/public/

It showing the content of layout page but $this->layout()->content is not working (ie index action of index controller)

What is wrong with this code

Upvotes: 0

Views: 1003

Answers (2)

Deepak Lamichhane
Deepak Lamichhane

Reputation: 22704

You need to echo your content. Either you can use

<?= $this->layout()->content ?> 

OR

<?php echo $this->layout()->content ?>

Upvotes: 0

Liyali
Liyali

Reputation: 5693

You need to echo your content.

<?= $this->layout()->content ?> will do what you want!

Upvotes: 1

Related Questions