SitePoint Sponsor

User Tag List

Page 4 of 4 FirstFirst 1234
Results 76 to 84 of 84
  1. #76
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    I was referring to captainccs implementation not yours to clear things up. What he is doing it presentational what you were doing not so much.
    When you're inside a form there is a lot of presentation and a lot of data, input tags are both, so it gets difficult to keep them strictly separate. In practice, working with a designer, I would expect him to show me a model of what he wants the form to look like and I would implement both, the look and feel and the functionality, the data.

    In practice I would expect the designer to tell me: "Put that form in this here square space." The form would be in a separate file, an include file, so the designer never have to mess with it. Until now I have managed to keep the functionality reduced to a php include or two. I don't see that changing.

    If you are making good use of CSS, the designer can make changes to the look and feel of the form without ever looking at the code, just by adjusting the various class attributes.
    Denny Schlesinger
    web services

  2. #77
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    This is something along your lines that I attempted a while back. However, there isn't really a benefit to it all. Its just not very practical. Its much easier to just write it straight then attempt to represent each tag/element as a object.

    PHP Code:
    $blogTitleLabel = new Element('label');
    $blogTitleLabel
    ->addAttribute('name','blog-title');

    $blogTitleInput = new Element('input');
    $blogTitleInput
    ->addAttribute('id','blog-title')
    ->
    addAttribute('value','')
    ->
    addAttribute('type','text')
    ->
    addAttribute('maxlength','40');

    $blogTitleListItem = new Element('li');
    $blogTitleListItem
    ->addAttribute('class','blog-title');

    $ol1 = new Element('ol');
    $ol1
    ->addAttribute('class','fields');

    $ol2 = new Element('ol');
    $ol2
    ->addAttribute('class','controls');

    $fieldset1 = new Element('fieldset');
    $fieldset1
    ->addAttribute('class','fields');

    $fieldset2 = new Element('fieldset');
    $fieldset2
    ->addAttribute('class','controls');

    $form = new Element('form');
    $form
    ->addAttribute('method','post')
    ->
    addAttribute('action','/index.php');

    $blogTitleListItem
    ->addChild($blogTitleLabel)
    ->
    addChild($blogTitleInput);

    $ol1
    ->addChild($blogTitleListItem);

    $fieldset1->addChild($ol1);
    $fieldset2->addChild($ol2);

    $form
    ->addChild($fieldset1)
    ->
    addChild($fieldset2);

    echo 
    $form->render(); 
    Just to show you some output although its invalid because I abandoned this idea and never finished it.

    HTML Code:
    	<form method="post" action="/index.php">
    		<fieldset class="fields">
    			<ol class="fields">
    				<li class="blog-title">
    					<label name="blog-title">
    					</label>
    					<input id="blog-title" value="" type="text" maxlength="40">
    					</input>
    
    				</li>
    			</ol>
    		</fieldset>
    		<fieldset class="controls">
    			<ol class="controls">
    			</ol>
    		</fieldset>
    
    	</form>
    These are the two primary classes. I would have added classes for SimpleText and ClosedElements, but like I said I abandoned this idea a while back because it didn't seem to be all that practical.

    PHP Code:
    <?php
    class Attribute {

        protected 
    $name;
        protected 
    $value;
        
        protected 
    $attribute;
        
        protected 
    $active true;
        
        public function 
    __construct($name='',$value='') {
        
            
    $this->setName($name);
            
    $this->setValue($value);
        
        }
        
        public function 
    setName($name) {
        
            
    $this->name $name;
        
        }
        
        public function 
    setValue($value) {
        
            
    $this->value $value;
        
        }
        
        public function 
    getName() {
        
            return 
    $this->name;
        
        }
        
        public function 
    getValue() {
        
            return 
    $this->value;
        
        }
        
        public function 
    addAttribute($name,$value) {
        
            if(
    $this->attribute) {
            
                
    $this->attribute->addAttribute($name,$value);
            
            } else {
            
                
    $this->attribute = new Attribute($name,$value);
            
            }
            
            return 
    $this;
        
        }
        
        public function 
    render($all=true) {
        
            
    $str $this->active?$this->getName().'="'.$this->getValue().'"':'';
            
            if(
    $all && $this->attribute) {
                
                
    $str.= ' '.$this->attribute->render();
                
            }
            
            return 
    $str;
        
        }
        
        public function 
    getAttribute($index=1) {
        
            return (
    $index!=&& $this->attribute)?$this->attribute->getAttribute(--$index):$this->attribute;
            
        }

    }

    class 
    Element {

        protected 
    $name;    
        protected 
    $attribute;
        
        protected 
    $sibling;
        protected 
    $child;

        public function 
    __construct($name) {
        
            
    $this->setName($name);
        
        }
        
        public function 
    addAttribute($name,$value) {
        
            if(
    $this->attribute) {
            
                
    $this->attribute->addAttribute($name,$value);
            
            } else {
            
                
    $this->attribute = new Attribute($name,$value);
            
            }
            
            return 
    $this;
        
        }
        
        public function 
    addSibling(Element $element) {
        
            if(
    $this->sibling) {
            
                
    $this->sibling->addSibling($element);
            
            } else {
            
                
    $this->sibling $element;
            
            }
            
            return 
    $this;
        
        }
        
        public function 
    addChild(Element $element) {
        
            if(
    $this->child) {
            
                
    $this->child->addSibling($element);
            
            } else {
            
                
    $this->child $element;
            
            }
            
            return 
    $this;
        
        }
        
        public function 
    setName($name) {
        
            
    $this->name $name;
        
        }
        
        public function 
    getName() {
        
            return 
    $this->name;
        
        }
        
        public function 
    render($runner=1) {
        
            
    $str implode('',array_fill(0,$runner,"\t")).'<'.$this->getName();    
            
    $str.=  $this->attribute?' '.$this->attribute->render().'>'."\n":'>'."\n";
            
            if(
    $this->child) {
            
                
    $str.= $this->child->render(($runner+1));
            
            }
            
            
    $str.= implode('',array_fill(0,$runner,"\t")).'</'.$this->name.'>'."\n";
            
            if(
    $this->sibling) {
            
                
    $str.= $this->sibling->render($runner)."\n";
            
            }
            
            return 
    $str;
        
        }
        
        public function 
    getSibling($index=1) {
        
            return (
    $index!=&& $this->sibling)?$this->sibling->getSibling(--$index):$this->sibling;
        
        }

        public function 
    getChild($index=1) {
        
            return (
    $index!=&& $this->child)?$this->child->getSibling(--$index):$this->child;
        
        }

    }

  3. #78
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    This is something along your lines that I attempted a while back. However, there isn't really a benefit to it all. Its just not very practical. Its much easier to just write it straight then attempt to represent each tag/element as a object.
    Thanks for that! There certainly are a lot of similarities and I see where you are coming from. So far, I've gotten a lot of good milage out of there very specific classes I have been using: select, radiobuttons and checkboxes. These are really tedious to write by hand. If I share your experience I might stop there but I'm trying to redo my procedural framework in OOP and I'm not entirely sure just where I'll wind up.
    Denny Schlesinger
    web services

  4. #79
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    I've always found this interesting just never practical. However, what you could do is something similar to the below. Define classes for closed elements and text nodes. Text nodes can't have things added as children and closed elements can't either.

    PHP Code:
    class SimpleText extends Element {

        protected 
    $value;

        public function 
    __construct($value) {
        
            
    $this->value $value;
        
        }

        final public function 
    addChild(Element $element) {
        
            return 
    $this;
        
        }
        
        final public function 
    getChild($index=1) {
        
            return 
    null;
        
        }
        
        public final function 
    render($runner=1) {
        
            
    $str $this->value
            
            if(
    $this->sibling) {
            
                
    $str.= $this->sibling->render($runner)."\n";
            
            }
            
            return 
    $str;    
        
        }

    }

    class 
    ClosedElement extends Element {

        final public function 
    addChild(Element $element) {
        
            return 
    $this;
        
        }
        
        final public function 
    getChild($index=1) {
        
            return 
    null;
        
        }
        
        final public function 
    render($runner=1) {

            
    $str implode('',array_fill(0,$runner,"\t")).'<'.$this->getName();    
            
    $str.=  $this->attribute?' '.$this->attribute->render().'>'."\n":'>'."\n";    
            
            if(
    $this->sibling) {
            
                
    $str.= $this->sibling->render($runner)."\n";
            
            }
            
            return 
    $str;        
        
        }


    Then you could just begin building tag classes and maybe even include a list of valid attributes or something.

    PHP Code:
    class Paragraph extends Element {

        public function 
    __construct() {
        
            
    parent::__construct('p');
        
        }
        
        public function 
    addChild(SimpleText $text) {
        
            return 
    parent::addChild($text);
        
        }

    }

    class 
    FormSelect extends Element {

        public function 
    __construct() {
        
            
    parent::__construct('select');
        
        }
        
        public function 
    addChild(FormOption $option) {
        
            return 
    parent::addChild($option);
        
        }

    }

    class 
    FormOption extends Element {

        public function 
    __construct() {
        
            
    parent::__construct('option');
        
        }

        public function 
    addChild(SimpleText $text) {
        
            return 
    parent::addChild($text);
        
        }

    }

    class 
    FormInput extends ClosedElement {

        public function 
    __construct() {
        
            
    parent::__construct('input');
        
        }


    For example, a select element can only have options added as children so the parent addChild is overwritten to only allow option elements be added as children.

  5. #80
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    You got me interested in this anyway.

    PHP Code:
    $page = new DTStrict4();

    $html = new Element('html');

    $page->addSibling($html);

    $head = new Element('head');
    $body = new Element('body');

    $html->addChild($head)->addChild($body);

    $head->addChild(new HTitle('Project-Pad Project Form'))->addChild(new CSS('/include/css/base.css'));

    $form = new HForm($_SERVER['PHP_SELF'],'POST','project-form');
    $body->addChild($form);

    $projectIdInput = new FormInput();
    $projectIdInput->addAttribute('name','project[id]')->addAttribute('type','hidden');

    $form->addChild($projectIdInput);

    $fieldsFieldset = new Fieldset(null,'fields');
    $controlsFieldset = new Fieldset(null,'controls');

    $form->addChild($fieldsFieldset)->addChild($controlsFieldset);

    $ol1 = new OL('project-data');
    $ol2 = new OL('form-controls');

    $fieldsFieldset->addChild(new Legend('Project Form'));

    $fieldsFieldset->addChild($ol1);
    $controlsFieldset->addChild($ol2);

    $titleLi = new LI();
    $categoryLi = new LI();
    $rangeLi = new LI();
    $messageLi = new LI();

    $ol1->addChild($titleLi)->addChild($categoryLi)->addChild($rangeLi)->addChild($messageLi);

    $titleInput = new FormInput();
    $titleInput->addAttribute('name','project[title]')->addAttribute('type','text')->addAttribute('maxlength','40')->addAttribute('id','project-title');

    $titleLi->addChild(new Label('Project Title:','project-title'))->addChild($titleInput);

    $categorySelect = new FormSelect();
    $categorySelect->addAttribute('id','project-category')->addAttribute('name','project[category]');
    $categoryLi->addChild(new Label('Project Category:','project-category'))->addChild($categorySelect);

    $rangeSelect = new FormSelect();
    $rangeSelect->addAttribute('id','project-range')->addAttribute('name','project[range]');
    $rangeLi->addChild(new Label('Project Range:','project-range'))->addChild($rangeSelect);

    $messageTextarea = new Textarea();
    $messageTextarea->addAttribute('id','project-message')->addAttribute('name','project[message]')->addAttribute('cols','60')->addAttribute('rows','15');
    $messageLi->addChild(new Label('Project Description:','project-message'))->addChild($messageTextarea);

    $resetButton = new FormInput();
    $resetButton->addAttribute('type','reset')->addAttribute('name','reset')->addAttribute('value','Reset Form');

    $submitButton = new FormInput();
    $submitButton->addAttribute('type','submit')->addAttribute('name','submit')->addAttribute('value','Submit Form');

    $resetLi = new LI();
    $submitLi = new LI();

    $ol2->addChild($resetLi->addChild($resetButton));
    $ol2->addChild($submitLi->addChild($submitButton));

    // fill tempate with data
    foreach(Category::find('all',array('sort'=>array('name'=>'ASC'))) as $category) {
        
    $option = new FormOption(ucwords($category->name),$category->id);
        if(isset(
    $_POST['project']['category']) && $_POST['project']['category']==$category->id) { $option->addAttribute('selected','selected'); }
        
    $categorySelect->addChild($option);
    }

    foreach(
    Range::find('all',array('sort'=>array('min_value'=>'ASC'))) as $range) {
        
    $option = new FormOption(ucwords('$'.$range->min_value.'&nbsp;&ndash;&nbsp;$'.$range->max_value),$range->id);
        if(isset(
    $_POST['project']['range']) && $_POST['project']['range']==$range->id) { $option->addAttribute('selected','selected'); }
        
    $rangeSelect->addChild($option);
    }

    if(isset(
    $_POST['project']['message']) && !empty($_POST['project']['message'])) $messageTextarea->addChild(new SimpleText($_POST['project']['message']));
    if(isset(
    $_POST['project']['title']) && !empty($_POST['project']['title'])) $titleInput->addAttribute('value',$_POST['project']['title']);

    echo 
    $page->render(); 

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Project-Pad Project Form</title>
    		<link rel="stylesheet" type="text/css" href="/include/css/base.css">
    
    	</head>
    	<body>
    		<form action="/project_form_dynamic.php" method="POST" id="project-form">
    			<input name="project[id]" type="hidden">
    			<fieldset class="fields">
    				<legend>Project Form</legend>
    				<ol id="project-data">
    					<li>
    
    						<label name="project-title">Project Title:</label>
    						<input name="project[title]" type="text" maxlength="40" id="project-title">
    					</li>
    					<li>
    						<label name="project-category">Project Category:</label>
    						<select id="project-category" name="project[category]">
    							<option value="5">Advertising</option>
    
    							<option value="4">Copywriting</option>
    							<option value="3">Graphic Design</option>
    							<option value="6">Marketing</option>
    							<option value="2">Mysql</option>
    							<option value="1">Web Design</option>
    						</select>
    
    					</li>
    					<li>
    						<label name="project-range">Project Range:</label>
    						<select id="project-range" name="project[range]">
    							<option value="1">$10&nbsp;&ndash;&nbsp;$50</option>
    							<option value="2">$50&nbsp;&ndash;&nbsp;$100</option>
    
    							<option value="3">$100&nbsp;&ndash;&nbsp;$200</option>
    							<option value="4">$200&nbsp;&ndash;&nbsp;$500</option>
    							<option value="5">$500&nbsp;&ndash;&nbsp;$1000</option>
    							<option value="6">$1000&nbsp;&ndash;&nbsp;$2000</option>
    							<option value="7">$2000&nbsp;&ndash;&nbsp;$5000</option>
    
    							<option value="8">$5000&nbsp;&ndash;&nbsp;$10000</option>
    							<option value="9">$10000&nbsp;&ndash;&nbsp;$50000</option>
    							<option value="10">$50000&nbsp;&ndash;&nbsp;$200000</option>
    						</select>
    					</li>
    					<li>
    
    						<label name="project-message">Project Description:</label>
    						<textarea id="project-message" name="project[message]" cols="60" rows="15"></textarea>
    					</li>
    				</ol>
    			</fieldset>
    			<fieldset class="controls">
    				<ol id="form-controls">
    					<li>
    
    						<input type="reset" name="reset" value="Reset Form">
    					</li>
    					<li>
    						<input type="submit" name="submit" value="Submit Form">
    					</li>
    				</ol>
    			</fieldset>
    		</form>
    	</body>
    
    </html>
    Basically, it will not only build all the HTML, but do in a easy to read manor also. I can't stand auto generators that just result in one long string.

    Example of some of the subclasses I'll leave the rest up to you if you feel so inclined to create something similar:

    PHP Code:
    class Paragraph extends Element {

        public function 
    __construct($text=null) {
        
            
    parent::__construct('p');
            
            if(
    $text) {
                
    $this->addChild(new SimpleText($text));
            }
        
        }
        
        public function 
    addChild(SimpleText $text) {
        
            return 
    parent::addChild($text);
        
        }

    }

    class 
    FormSelect extends Element {

        public function 
    __construct() {
        
            
    parent::__construct('select');
        
        }
        
        public function 
    addChild(FormOption $option) {
        
            return 
    parent::addChild($option);
        
        }

    }

    class 
    FormOption extends Element {

        public function 
    __construct($text=null,$value=null) {
        
            
    parent::__construct('option');
            
            if(
    $text) {
                
    $this->addChild(new SimpleText($text));
            }
            
            if(
    $value) {
                
    $this->addAttribute('value',$value);
            }
        
        }

        public function 
    addChild(SimpleText $text) {
        
            return 
    parent::addChild($text);
        
        }

    }

    class 
    FormInput extends ClosedElement {

        public function 
    __construct() {
        
            
    parent::__construct('input');
        
        }

    }

    class 
    Div extends Element {

        public function 
    __construct($id=null,$class=null) {
        
            
    parent::__construct('div');    
            
            if(
    $id) {
                
    $this->addAttribute('id',$id);
            }
            
            if(
    $class) {
                
    $this->addAttribute('class',$class);
            }
        
        }

    }

    class 
    HForm extends Element {

        public function 
    __construct($action=null,$method=null,$id=null,$class=null) {
        
            
    parent::__construct('form');
            
            if(
    $action$this->addAttribute('action',$action); 
            if(
    $method$this->addAttribute('method',$method); 
            if(
    $id$this->addAttribute('id',$id); 
            if(
    $class$this->addAttribute('class',$class); 
        
        }

    }

    class 
    Fieldset extends Element {

        public function 
    __construct($id=null,$class=null) {
        
            
    parent::__construct('fieldset');
            
            if(
    $id$this->addAttribute('id',$id);
            if(
    $class$this->addAttribute('class',$class);
        
        }

    }

    class 
    OL extends Element {

        public function 
    __construct($id=null,$class=null) {
        
            
    parent::__construct('ol');
            
            if(
    $id$this->addAttribute('id',$id);
            if(
    $class$this->addAttribute('class',$class);
        
        }
        
        public function 
    addChild(LI $element) {
        
            return 
    parent::addChild($element);
        
        }

    }

    class 
    UL extends Element {

        public function 
    __construct($id=null,$class=null) {
        
            
    parent::__construct('ul');
            
            if(
    $id$this->addAttribute('id',$id);
            if(
    $class$this->addAttribute('class',$class);
        
        }
        
        public function 
    addChild(LI $element) {
        
            return 
    parent::addChild($element);
        
        }

    }

    class 
    LI extends Element {

        public function 
    __construct($id=null,$class=null) {
        
            
    parent::__construct('li');
            
            if(
    $id$this->addAttribute('id',$id);
            if(
    $class$this->addAttribute('class',$class);
        
        }


    Here is an example of using it to create a table component:

    PHP Code:
    // projects table
            
            
    $filter = array();
            
    $filter['status<>'] = 0;
            
    $time time();
            
    $projects=
                
    Project::find(
                    
    'all'
                    
    ,array(
                        
    'include'=>array('range','category','user','bids')
                        ,
    'condition'=>array('won'=>'Project.id NOT IN (SELECT DISTINCT project_id FROM won_projects)')
                        ,
    'conditionMap'=>'{won}'
                        
    ,'filter'=>$filter
                        
    ,'group'=>'id'
                        
    ,'dynamic'=>array(
                            
    'bid_count'=>'COUNT(Bid.project_id)'
                            
    ,'days'=>array('TIMESTAMPDIFF(DAY,Project.created,FROM_UNIXTIME(?))',$time)
                        )
                        ,
    'limit'=>100
                        
    ,'offset'=>0
                        
    ,'sort'=>array('created'=>'DESC')
                    )
                    ,array()
                    ,array()
                    ,array(
    'select'=>'name')
                    ,array(
                        
    'select'=>'created'
                        
    ,'include'=>'user'
                        
    ,'require'=>false
                        
    ,'condition'=>array('stat'=>'(Bid.status IS NULL OR Bid.status <> 0)')
                        ,
    'conditionMap'=>'{stat}'
                    
    )
                    ,array(
    'select'=>'name','require'=>false)
                );

    $projectsTable = new Element('table');
    $projectsTable->addAttribute('class','projects');

    $projectsTableHead = new Element('thead');
    $projectsTableBody = new Element('tbody');

    $projectsTable->addChild($projectsTableHead)->addChild($projectsTableBody);

    $projectsHeadTitle = new Element('th');
    $projectsHeadBids = new Element('th');
    $projectsHeadBudget = new Element('th');
    $projectsHeadCategory = new Element('th');
    $projectsHeadPosted = new Element('th');

    $projectsHeadTitle
    ->addChild(new SimpleText('Title'))
    ->
    addAttribute('class','project-title');

    $projectsHeadBids
    ->addChild(new SimpleText('Bids'))
    ->
    addAttribute('class','project-bids');

    $projectsHeadBudget
    ->addChild(new SimpleText('Budget'))
    ->
    addAttribute('class','project-range');

    $projectsHeadCategory
    ->addChild(new SimpleText('Category'))
    ->
    addAttribute('class','project-category');

    $projectsHeadPosted
    ->addChild(new SimpleText('Posted'))
    ->
    addAttribute('class','project-created');

    $projectsTableHead
    ->addChild($projectsHeadTitle)
    ->
    addChild($projectsHeadBids)
    ->
    addChild($projectsHeadBudget)
    ->
    addChild($projectsHeadCategory)
    ->
    addChild($projectsHeadPosted);

    foreach(
    $projects as $project) {

        
    $row = new Element('tr');
        
        
    $projectsTableBody
        
    ->addChild($row);
        
        
    $projectTitle = new Element('td');
        
    $projectBids = new Element('td');
        
    $projectBudget = new Element('td');
        
    $projectCategory = new Element('td');
        
    $projectPosted = new Element('td');
        
        
    $row
        
    ->addAttribute('class','project')
        ->
    addChild($projectTitle)
        ->
    addChild($projectBids)
        ->
    addChild($projectBudget)
        ->
    addChild($projectCategory)
        ->
    addChild($projectPosted);
        
        
    $projectTitleAnchor = new Anchor('/index.php/project/'.$project->id);
        
    $projectTitleAnchor
        
    ->addChild(new SimpleText($project->title));
        
        
    $projectTitle
        
    ->addChild($projectTitleAnchor)
        ->
    addAttribute('class','project-title');
        
        
    $projectBids
        
    ->addChild(new SimpleText($project->bid_count))
        ->
    addAttribute('class','project-bids');
            
        
    $projectBudget
        
    ->addChild(new SimpleText('$'.$project->range->min_value.'&ndash;$'.$project->range->max_value))
        ->
    addAttribute('class','project-range');
            
        
    $projectCategory
        
    ->addChild(new SimpleText(ucwords($project->category->name)))
        ->
    addAttribute('class','project-category');
        
        
    $day $project->days==|| $project->days == 1?$project->days==0?'today':'yesterday':$project->days.' days ago';
        
    $projectPosted
        
    ->addChild(new SimpleText($day))
        ->
    addAttribute('class','project-created');

    }

    echo 
    "\n".$projectsTable->render(); 
    HTML Code:
    <table class="projects">
    	<thead>
    		<th class="project-title">Title</th>
    
    		<th class="project-bids">Bids</th>
    		<th class="project-range">Budget</th>
    		<th class="project-category">Category</th>
    		<th class="project-created">Posted</th>
    	</thead>
    	<tbody>
    		<tr class="project">
    
    			<td class="project-title">
    				<a href="/index.php/project/13">My new project *****es!!!</a>
    			</td>
    			<td class="project-bids">0</td>
    			<td class="project-range">$5000&ndash;$10000</td>
    			<td class="project-category">Graphic Design</td>
    
    			<td class="project-created">2 days ago</td>
    		</tr>
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/12">new title</a>
    			</td>
    			<td class="project-bids">0</td>
    
    			<td class="project-range">$50&ndash;$100</td>
    			<td class="project-category">Marketing</td>
    			<td class="project-created">3 days ago</td>
    		</tr>
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/6">My new project</a>
    
    			</td>
    			<td class="project-bids">2</td>
    			<td class="project-range">$100&ndash;$200</td>
    			<td class="project-category">Copywriting</td>
    			<td class="project-created">7 days ago</td>
    		</tr>
    
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/11">My new project</a>
    			</td>
    			<td class="project-bids">2</td>
    			<td class="project-range">$100&ndash;$200</td>
    			<td class="project-category">Copywriting</td>
    
    			<td class="project-created">12 days ago</td>
    		</tr>
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/5">wqdwq d qw d qw d q wd  qw d</a>
    			</td>
    			<td class="project-bids">0</td>
    
    			<td class="project-range">$200&ndash;$500</td>
    			<td class="project-category">Mysql</td>
    			<td class="project-created">16 days ago</td>
    		</tr>
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/4">wqdwq d qw d qw d q wd  qw d</a>
    
    			</td>
    			<td class="project-bids">0</td>
    			<td class="project-range">$200&ndash;$500</td>
    			<td class="project-category">Mysql</td>
    			<td class="project-created">16 days ago</td>
    		</tr>
    
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/3">Looking for web designer</a>
    			</td>
    			<td class="project-bids">1</td>
    			<td class="project-range">$1000&ndash;$2000</td>
    			<td class="project-category">Graphic Design</td>
    
    			<td class="project-created">17 days ago</td>
    		</tr>
    		<tr class="project">
    			<td class="project-title">
    				<a href="/index.php/project/2">Small On going assignment</a>
    			</td>
    			<td class="project-bids">0</td>
    
    			<td class="project-range">$100&ndash;$200</td>
    			<td class="project-category">Copywriting</td>
    			<td class="project-created">17 days ago</td>
    		</tr>
    	</tbody>
    </table>

  6. #81
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    Seems like something like this might be useful. I got the idea from you talking about about components.

    PHP Code:
    class CategoryMenuComponent extends Element {

        public function 
    __construct($categories,$category=null) {
        
            
    parent::__construct('ul');        
            
    $this->addAttribute('id','category-nav');
            
            
    $this->_build($categories,$category);
        
        }
        
        protected function 
    _build($categories,$cCategory) {

            foreach(
    $categories as $category) {

                
    $categoryLi = new LI();
                
    $this
                
    ->addChild($categoryLi);
        
                
    $categoryAnchor = new Anchor('/index.php/projects/'.$category->id);    
                
    $categoryAnchor
                
    ->addChild(new SimpleText(ucwords($category->name).'&nbsp;<span class="project-count">'.$category->project_count.'</span>'));
        
                
    $categoryLi
                
    ->addChild($categoryAnchor);
                
                if(
    $cCategory && $cCategory->id == $category->id$categoryAnchor->addAttribute('class','current');
        
            }    
        
        
        }


    Then the only code you would need to worry about in the view is to create the object and pass the necessary arguments. The component would take care of building out the HTML though.

    PHP Code:
    $categories = new CategoryMenuComponent($categories,$categories[2]);
    echo 
    $categories->render(); 
    HTML Code:
    
    
    
    
    
    
    <ul id="category-nav">
    	<li>
    		<a href="/index.php/projects/4">Copywriting&nbsp;<span class="project-count">3</span></a>
    	</li>
    
    	<li>
    		<a href="/index.php/projects/2">Mysql&nbsp;<span class="project-count">2</span></a>
    	</li>
    	<li>
    		<a href="/index.php/projects/3" class="current">Graphic Design&nbsp;<span class="project-count">2</span></a>
    	</li>
    	<li>
    
    		<a href="/index.php/projects/6">Marketing&nbsp;<span class="project-count">1</span></a>
    	</li>
    	<li>
    		<a href="/index.php/projects/1">Web Design&nbsp;<span class="project-count">0</span></a>
    	</li>
    	<li>
    		<a href="/index.php/projects/5">Advertising&nbsp;<span class="project-count">0</span></a>
    
    	</li>
    </ul>
    Something like this now might actually be useful. Essentially a component based framework which would mean you could eliminate needless repetition of HTML.

  7. #82
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is already the DOM, which supplies an albeit verbose interface to programmatically manipulating an xml/html document. You could build some helpers to make it more fluent to generate elements, but using a php's native DOM extension would make sense.

    This concept has been tried before, but there are a couple of problems with it. Performance is a major one; It's a lot faster to do a bit of string manipulation, than to have the entire DOM in memory. With a native (libxml) DOM extension, it has become more feasible though. CPUs are also getting more powerful every day.

    Another problem with the concept, is that there is already a very established workflow based on text-representations of markup, rather than a programmatical api. This means that the change is disrupting a lot of common practises. Whether that's good or bad, it does take some effort. One thing in particular, is that in many shops the people writing markup aren't comfortable with a programmatical interface. Their tools are tailored to working with markup, so it's not an easy transition.

    All that considered, I think this approach works best for very complex interfaces (such as forms), where you'd need a programmer approach anyway. A thing that'd make it more attractive, would be if you can integrate the template approach with the DOM approach in a smooth way. I wrote about one such approach recently, but I haven't tried it in practise, so I'm not sure how well it'll work.

  8. #83
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    Seems like something like this might be useful. I got the idea from you talking about about components.

    [snip]

    Something like this now might actually be useful. Essentially a component based framework which would mean you could eliminate needless repetition of HTML.
    I'm glad you are warming up to the idea. My next to last project was creating something like this but using procedural code. In fact, it was a web page HTML generator that hid all the complexity of creating the pages. The form has three sections:

    1. Content writing for page owner
    2. Tags for SEO
    3. Back end for developer


    But the content writing can only take text and images, very similar to how your write forum posts. The generator uses a combination of templates and components.

    We have a saying in Spanish, "Neither bald nor with two wigs." I would not want to take on a web designer's task. Much better to have the designer create the page (the template, actually) in DreamWeaver or whatever his favorite tool is and to use it as a component in the rendering engine. The developer would build other kinds of components and the rendering engine produces the final output.
    Denny Schlesinger
    web services

  9. #84
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kyberfabrikken
    This concept has been tried before, but there are a couple of problems with it. Performance is a major one;
    So wouldn't a simple tree be better in those regards then using the DOM?

    Its an interesting idea, but I would be worried about performance.

    Quote Originally Posted by captainccs
    I'm glad you are warming up to the idea.
    I think the idea has merit considering the advantage of the reusable code base.


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
  •