SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    General: Help on passing a layout to MVC structure (for ZendFramework).

    Hello all,

    Please have a look of both links here, that represent a layout structure of a given website:

    The homepage:
    http://www.help.nuvemk.com/mvc_zend/home_page.png


    The secondary pages:
    http://www.help.nuvemk.com/mvc_zend/secondary_pages.png


    Newbie here, so don't get to complicated on me. Please. (only if you REALLY must).

    I do have a lot of questions, but I believe they should be quick answered by anyone used to mvc structures and oo in general.


    1) About the navigation:
    1.1) Should we draw the navigation on our Layout?

    1.2) Or should we repeat the code for each view?

    1.3) Or a helper? If this generates to many discussion, please just advice one with restrictions.

    1.3.1) If we do it on the layout, how can we have the proper
    menu item highlighted if the user is on a given page ?"


    2) About the pink zone:
    It will have a list of latest news comming from the database.
    This list of latest news will be available on ALL pages.

    2.1) If we do it on the layout, is there an issue to have a controller
    and a model for our layout?

    2.2) Is there a third option more reliable?

    About HOME and SECONDARY pages:
    3) As we can see, the HOME PAGE (singular) and the Secundary Pages (plural),
    are quite different on their look. How can we deal with this?
    3.1) Should we have two layouts, one for the HOME PAGE and another for the
    secondary pages?

    3.2)
    Or shouldn't we have a layout for the home page at all,
    since it's a solo page, hence, a view will sufice?

    4) About the majority of examples seen:
    On the secondary pages, I believe we can't simply have a layout with a header and a footer, and between them, have:
    PHP Code:
    <?php echo $this->layout()->content?>
    Like so many examples out there. Not just that.

    Between the header and the footer we have not only our view specific stuff, but we also have a pink box that will be equal on every page, and a navigation that it's between them as well.
    4.1) I'm wondering if we can have:
    PHP Code:
    <?php echo $this->layout()->content?>
    but also:
    PHP Code:
    <?php echo $this->layout()->bigheadings?>


    Kind Regards,
    Márcio

  2. #2
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I would say best practice is to do a partial view for your layouts. Do a different layout for the main and the sub pages. This way you can pre plan for the future if you need to use yet again another different layout for whatever reason (e.g. promotion page, landing page). I would also recommend you buy the Zend Framework book from phpArchitects.
    Have a good day.

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thanks for the info.
    I have "Zend Framework 1.8 Web Application Development" (it's quite advanced).
    And "Easy PHP Websites with the Zend Framework".
    More accessible for me right now. I feel I need to practice a lot, by seeing layout sketches and try to figure out, what on that layout sketches should be a Zend Layout, a Zend View etc...
    That's why I'm asking those (the most specific I can) questions. If you can specify a little more regarding those questions above, I would be more then glad.


    Thanks a lot for your reply.
    Márcio

  4. #4
    SitePoint Zealot romance's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oikram View Post

    1) About the navigation:
    1.1) Should we draw the navigation on our Layout?

    1.2) Or should we repeat the code for each view?

    1.3) Or a helper? If this generates to many discussion, please just advice one with restrictions.

    1.3.1) If we do it on the layout, how can we have the proper
    menu item highlighted if the user is on a given page ?"
    I'd use a view helper for the navigation. you can then either pass the current controller/action name to the view helper via the controller (perhaps in the preDispatch() method so its available in all your actions)

    $this->view->urlParams = $this->_request->getParams();


    then in the layout call:

    Code:
    <?=$this->myNavigationMenu($this->urlParams);?>
    or you could grab an instance of the front controller in the view helper code (although this might not be 'pure' MVC)

    Both of these will allow you to find the current action being called allowing you to highlight the current navigational item (or do a breadcrumb etc)

    Here's an example of a view helper you could use to grab some news articles and render them http://www.pastie.org/955606


    There's also Zend Navigation, although i've never used this.


    Quote Originally Posted by oikram View Post

    2) About the pink zone:
    It will have a list of latest news comming from the database.
    This list of latest news will be available on ALL pages.

    2.1) If we do it on the layout, is there an issue to have a controller
    and a model for our layout?

    2.2) Is there a third option more reliable?
    If the text is going to be static i'd use a partial. if not i'd use a view helper. You could cache the contents of the view helper to cut down on db calls.


    About HOME and SECONDARY pages:
    3) As we can see, the HOME PAGE (singular) and the Secundary Pages (plural),
    are quite different on their look. How can we deal with this?
    3.1) Should we have two layouts, one for the HOME PAGE and another for the
    secondary pages?

    I'd have two separate layouts, just have $this->_helper->layout->setLayout("homepage"); for your index action.



    4) About the majority of examples seen:
    On the secondary pages, I believe we can't simply have a layout with a header and a footer, and between them, have:
    PHP Code:
    <?php echo $this->layout()->content?>
    Like so many examples out there. Not just that.
    I'd use partials for your header and footer if you feel they would change, but for some cases i'd just leave in the layout as its only one file to change.

    Between the header and the footer we have not only our view specific stuff, but we also have a pink box that will be equal on every page, and a navigation that it's between them as well.
    4.1) I'm wondering if we can have:
    PHP Code:
    <?php echo $this->layout()->content?>
    but also:
    PHP Code:
    <?php echo $this->layout()->bigheadings?>
    You can use layout placeholders, so in your example of the 'big image that changes in each view' i'd setup a placeholder in the layout such as

    Code:
    <img src="<?=$this->placeholder('bigImage');?>" />
    then in each of your actions have

    $this->view->placeholder('bigImage')->set("foo.jpg");

    HTH

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot.

    That will allow me to kick off this first MVC with Zend Experience.
    Several concepts are completely new to me, I will investigate them.

    Thanks a lot again, for sharing your thoughts on "how you will do something like this".

    Márcio

  6. #6
    SitePoint Zealot romance's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good luck! One of the pros/cons of ZF is that there's many different ways to perform the same thing, so it can be daunting.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •