Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:05:20+00:00 2026-06-07T08:05:20+00:00

I cannot understand what is the difference between Zend_Layout and Zend_View . Here is

  • 0

I cannot understand what is the difference between Zend_Layout and Zend_View.

Here is a picture from Zend_Layout Tutorial.
enter image description here

Everything seems easy to understand. We have elements in <head>, we have Header, Navigation segment, Content segment, Sidebar and Footer. And it’s easy to understand how they are called. But I can’t see the difference between View and Layout. Why Navigation segment is called as Layout‘s property and Footer and Header are called as View property?

I tested Zend_Layout and interchanged them. I called the Navigation segment not as the Layout‘s property but as the View‘s property:

echo $this->layout()->nav;  // as in tutorial
echo $this->nav;    // used to call like this

And everything works fine. Not only for $nav, but for any variable. So what’s the difference?

I attach my experiment code here.
My experiment layout page consists of three main blocks:

  • header (html-code of header),
  • content (html-code of content block)
  • footer (html-код footer)

Here’s a script of template:

<!DOCTYPE html>
  <html>
   <head>
   </head>
      <body>
         <div header>
           <?php echo $this->header ?>     // it works
           <?php echo $this->layout()->header ?>  // and this variant also works
         </div>

         <div content>
            <?php echo $this->content ?>      // same thing, it is a View's property
            <?php echo $this->layout()->content ?>    // And it is a Layout's property
         </div>

         <div footer>
             <?php echo $this->footer ?>        // same thing
             <?php echo $this->layout->footer() ?>  // both work (one or another I mean)
         </div>
     </body>
  </html>

My code now:

$layout = Zend_Layout::startMvc();         // instantiate Layout
$layout->setLayoutPath('\TestPage\views');  // set the path where my layouts live

// And here's the most interesting
// Set Header layout first
$layout->setLayout('header');    // 'header.php' - is my file with html-code of the Header 
                                 // I pass only name 'header', and it makes 'header.php' from it. 
                                 // Predefined suffix is 'phtml' but I changed it to 'php'
$layout->getView()->button = "Button";   // assign some variable in the Header. Please pay attention, it is View's property
$layout->button_2 = "Button_2";   // and also I can assign this way. It's Layout's property now. And they both work
$headerBlock = $layout->render();   // render my Header and store it in variable

// the same procedures for the Content block
$layout->setLayout('content');
$layout->getView()->one = "One";   
$layout->two = "Two";
$contentBlock = $layout->render();   // render and store in the variable

//  and the same for the Footer
$layout->setLayout('footer');
$layout->getView()->foot = "Foot";   
$layout->foot_2 = "Foot_2";
$footerBlock = $layout->render();   // render and store in the variable

// and finally last stage - render whole layout and echo it
$lout->setLayout('main_template');
$layout->getView()->header = $headerBlock;   // again, I can do also $layout->header
$lout->content = $contentBlock;
$lout->getView()->footer = $footerBlock;
echo $lout->render();     // render and echo now.

And everything works fine, the page is displayed without errors. But I don’t know whether I use Zend_Layout and Zend_View right way or wrong way. Is it the right way to construct the page using Zend_Layout as I do it? What’s the difference between

echo $this->layout()->header // this
echo $this->header  // and this

Which variant is right one?

Also it seems I have double rendering: at first I render each segment. And then I render them again when I render my final template. Is this the right way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:05:22+00:00Added an answer on June 7, 2026 at 8:05 am

    See the answer I posted to your other (similar) question for some background. Zend_View is for rendering templates. Zend_Layout is a special type of template that contains one or more other templates. You should only ever have one layout on a page. The idea is that the layout contains the portions of the HTML that don’t really change between pages.

    Your code can be simplified to:

    The main layout file:

    <!DOCTYPE html>
      <html>
       <head>
       </head>
          <body>
             <?php echo $this->render('_header.phtml')?>
    
             <div content>
                <?php echo $this->layout()->content ?>
             </div>
    
             <?php echo $this->render('_footer.phtml)?>
         </body>
      </html>
    

    Usage:

    $layout = new Zend_Layout();
    $layout->setLayoutPath('\TestPage\views');
    $layout->setLayout('layout'); // this should be whatever you named your layout file
    
    $view = new Zend_View();
    $layout->content = $view->render('main_template.php'); // this is the part that changes between pages
    
    echo $layout->render();
    

    Don’t call startMvc() if you are not using the Zend Framework controller classes (which you don’t appear to be).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot effectively understand the difference between these two queries. select * from person
I cannot understand what is the difference between: #define WIDTH 10 and int width
I'm using for the firs time optional arguments but I cannot understand difference between
I have been struggling to understand the difference between Storyboards and coding in Objective-C.
I started studying about AppDomains, and I just cannot understand the difference between CreateInstance
I cannot understand the Java memory usage. I have an application which is executed
I cannot understand this query? select @:vfOutBalance+@:vfHSSubTotal+@3+orpartpayment,@:vfOutBalance+@:vfHSSubTotal from or_equip_upgrd_id what does @3 mean?
I would like to understand which is the difference between these two programming concepts.
I am trying my best to understand what is the difference between ADO.NET -
I have a problem in understanding the exact difference between modules and namespaces in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.