1

Today I was going through an already written code in zf2.

I was wondering about two lines in my layout folder in header.phtml file:

The lines <?php echo $this->layout()->face_login_url; ?> and <?php echo $face_login_url; ?>.

Both are giving the same output, so what is the difference?

1 Answer 1

2

The header.phtml is the view script of the layout. This is set on the 'root' view model instance and allows variables to be assigned to it just like the ViewModel instance returned from your controller actions.

These variables are extracted in the view, allowing the following to be used in the header.phtml file.

echo $this->face_login_url
echo $face_login_url;

The second line is a call to the Layout View Helper.

This helper allows easy access to the layout or 'root' view model (the same ViewModel instance that is used when rendering header.phtml). Therefore, the second line is actually accessing the same variable. To avoid unnecessary overhead this should only need to be used outside of header.phtml.

echo $this->layout()->face_login_url;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.