SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is this a Composite View?

    I'm trying to get a handle on the CompositView pattern, I think I have it, but maybe not
    PHP Code:
    require_once(MAIN_LIB.'/html/class.TemplateBuilder.php');

    abstract class 
    View{
        public 
    $template;

        function 
    renderView(){
            return 
    $this->template->getParsedTemplate();
        }
    }

    class 
    DefaultModuleView extends View {

        function 
    __construct(){
            
    $this->template = new TemplateBuilder("defaultView.html");
            
    $this->setDefaults();
        }
        
        function 
    set($tag$value){
            
    $this->template->assign($tag$value);
        }

        function 
    setDefaults(){
            
    $this->template->assign('<header>''This is the header content');
        }

    }

    class 
    ConfirmView extends DefaultModuleView {

        function 
    __construct(){
            
    parent::__construct();
        }

        function 
    assignConfirmation($message)    {
            
    $this->template->assign('<content>'$message);
        }

    }

    class 
    MenuView extends View {

        function 
    __construct($links){
            
    $this->template = new TemplateBuilder("defaultMenu.html");
            
    $this->buildMenu($links);
        }

        function 
    buildMenu($links)
        {
            foreach (
    $links as $link){
                
    $menu .= $link."<br>";
            }
            
            
    $this->template->assign('<menu>'$menu);
        }
    }

    abstract class 
    BaseController{
        abstract function 
    execute();
        abstract function 
    getView();
    }

    class 
    ConfirmationPageController extends BaseController {

        protected 
    $view;

        function 
    __construct(){}

        function 
    execute()
        {
            
    $menu = new MenuView(array("Link1""Link2""Link3""Link4"));
            
            
    $view = new ConfirmView();
            
    $view->set('<leftMenu>'$menu->renderView() );
            
    $view->assignConfirmation("This Worked!");

            
    $this->view $view;
        }

        function 
    getView()
        {
            return 
    $this->view;
        }

    }

    $controller = new ConfirmationPageController();
    $controller->execute();

    $view $controller->getView();
    echo 
    $view->renderView(); 

  2. #2
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like a composite view to me.

    JT

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    I use the Composite View also, and find that it works well for what I need to do.

    If you do a search on my postings, going back a bit you'll find various examples and the now current version of what I use just now, though unfortunately I can't repost the script for you


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
  •