SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 57 of 57
  1. #51
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On this point what I am working on at the moment and this is related to your point on multiple Views and Models [ie Header/Footer and List] is to have a class which specifies which if any given structures exists on a per page basis ?

    The Controller would initiate a given class which would generate each structure [ie Login/Logout box] and then pass over this to the View ?

    Wether you need one or more Models is specified by the said given class yes ? Don't know if this is exactly the perfect method to do this though...

    Sleepeasy [If I remember ?] was doing something like this based on events which basically does the same thing I suppose.

  2. #52
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    On this point what I am working on at the moment and this is related to your point on multiple Views and Models [ie Header/Footer and List] is to have a class which specifies which if any given structures exists on a per page basis ?

    The Controller would initiate a given class which would generate each structure [ie Login/Logout box] and then pass over this to the View ?

    Wether you need one or more Models is specified by the said given class yes ? Don't know if this is exactly the perfect method to do this though...

    Sleepeasy [If I remember ?] was doing something like this based on events which basically does the same thing I suppose.
    Well at this point the only issue I think I have trouble with understanding is the view. I know what the view does, but class wise a little confused. Like say your dealing with a db. You store the header and footer in the db (dont ask), so you would create a model to get the header and footer. You would then create a view to display that right? Because it will happen on every page so it would be a "default" function. Then say you want to add a menu which is also stored in a db. You would create another model or would you put this in the model for header and footer? And for the view part since it wont be on all the pages would you create a new view class and access the same model to get header/footer/menu or create a whole new view class to build the menu?

    Edit: For view wouldnt you just want to build the default template, then when you want to add to the template you just create new classes?

  3. #53
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my MVC framework I have and "Action" (part of the controller) called "ShowView". This action accesses some models and stores information that is global to all views. It is this same code that selects which view to instanciate, so when it does that, it then pre-loads the global information so the view does not even "know" about retrieving the global stuff.

    HTH

  4. #54
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    In my MVC framework I have and "Action" (part of the controller) called "ShowView". This action accesses some models and stores information that is global to all views. It is this same code that selects which view to instanciate, so when it does that, it then pre-loads the global information so the view does not even "know" about retrieving the global stuff.

    HTH
    So for example if you have a page that has say a recipe on it you would, through the controller, grab the global part of the view and then since the page shows the recipe you call to your recipe view from the controller and put it all together?

    Silly

  5. #55
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Sillysoft
    Well at this point the only issue I think I have trouble with understanding is the view. I know what the view does, but class wise a little confused. Like say your dealing with a db. You store the header and footer in the db (dont ask), so you would create a model to get the header and footer. You would then create a view to display that right?
    From my understanding of MVC, the model should not be dealing with anything that has to do with presentation. That means that the model should not be dealing with headers and footers.

    I've been playing around with the Mojavi framework.
    Here's how you'd do it with Mojavi.

    A http request is made and an Action(my understanding is that this is the model(?)) object is instantiated. This is where the application logic goes, the code that goes here, and that is called from here, should be oblivious to the fact that there even is a user interface(except that can pass data to the view object).
    After you execute whatever code you need to, you pass the data needed to the View class, that the view will need for presenting the data.
    The View class instantiates a "Renderer" object, which takes the controller and a template name in the constructor. You can set attributes of the Renderer that you've been passed from the model.
    So the relevant part in the View class looks something like:

    PHP Code:
            // alias inherited data for easy access
            
    $controller =& $this->_controller;

            
    // I put the data that needs to be passed to the view in the 
            // "request" object
            
    $request =& $this->_request;

            
    $userName $request->getAttribute('userName');

            
    // default_index.php is the template we're using
            
    $renderer =& new Renderer($controller'default_index.php');

            
    $renderer->setAttribute('examples_lib'$controller->getModuleDir() .
                                                    
    'lib/examples.inc');
            
    $renderer->setAttribute('title''Index');
            
    $renderer->setAttribute('userName'$userName);

            return 
    $renderer

    And the template(default_index.php) would looks
    something like this(the $template variable is already created for you):


    PHP Code:
    <?php require_once('_header.php'); ?>

    <div class="title">
        Welcome <?php echo $template['userName']; ?>
    </div>
    <br/>
    <div class="text">
        This is the index page for the Default module.
        <br/><br/>
        Please select an example from the following list:
        <br/><br/>
        <?php require_once($template['examples_lib']); ?>
    </div>



    <?php require_once('_footer.php'); ?>
    Of course you can use a third party templating engine if you want.

    So input goes to the model, where the business logic is contained, data related to presentation gets sent to the view. The view class formats/massages the data however it needs to, and then sends it to the template.
    The template gets parsed, and the output gets sent.

    At least that's the way it looks to me. When you use a framework like that, a lot of the MVC implemtation is hidden from you. Which is probably a good thing(unless you're wanting to learn how to implement an MVC framework).

    --ed

  6. #56
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    going through the archives I came across a Voostind rant! This paragraph helped me a lot:


    "My own approach to developing web sites is different from the normal approach ('normal' being the one taught in the average 'PHP & MySQL' book). Instead of working my way back from a set of pages given by a web designer to a fully dynamic database-driven PHP site, I view a web site as I view any software product (surprise!). Most of you will know by now I write my software object-oriented, and the same goes for websites. A page on a site is represented by a class, which has a method 'show' that prints the page. Of course that method doesn't do all the work by itself; it calls other methods on the page object itself to show different parts of the page (the header, the menu, the footer and so on). The nice thing about this is that I can easily write a subclass that overrides parts of the original class to generate a page that looks more or less the same, but works slightly different. A subclass 'NewsPage' for example might look in some subdirectory, read all text files in it, and print their contents, ordered on the dates the files were created. "

    You can read the template rant here:

    http://www.sitepointforums.com/showt...threadid=67849

    Silly

  7. #57
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...I can easily write a subclass that overrides parts of the original class to generate a page that looks more or less the same, but works slightly different.
    This is to me anyways the Design Pattern Template Module ?


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
  •