我在Procedural php 5年,最近我决定硬着头皮,进展到OOP。 现在我triyng创建一个基本的UI类来管理一个负责任的管理模板 此类网格 我希望能够做到这一点如何创建一个类正确的方式
$grid = new Grid();
// a span is an area the father and the widget is the son, so spans have widgets inside.
// a span a width of 6
$span1 = $grid->span("6");
// a new widget inside span1
$span1->widget("icon", "title1", "content1");
// another new widget inside span1
$span1->widget("icon", "title2", "content2");
// a span a width of 4
$span2 = $grid->span("4");
// a new widget inside span2
$span2->widget("icon", "title1", "content1");
// another new widget inside span2
$span2->widget("icon", "title2", "content2");
// echo /return results
$grid->render();
这是我到目前为止,但我不知道如何过关。
class Grid{
private $content;
private $innerContent;
private $spanResult;
private $widgetResult;
function span($size){
$this->size = $size;
$output = '<div class="span' . $size . '">';
$output .= $this->innerContent;
$output .= '</div>';
$this->spanResult .= $output;
}
function widget($icon, $title, $content){
$output = '<div class="widget widget-nopad">';
$output .= '<div class="widget-header"> <i class="icon-' . $icon . '"></i>';
$output .= '<h3>' . $title . '</h3>';
$output .= '</div>';
$output .= '<div class="widget-content">';
$output .= $content;
$output .= '</div>';
$output .= '</div>';
$this->widgetResult = $output;
}
function render(){
}
}
谢谢。
这应该是在代码审查 – 2014-12-04 21:13:19
我在那里发布,刚刚在那里,没有多少人在那里。 – 2014-12-04 21:17:33
这个问题似乎是脱离主题,因为它是关于[代码评论](http://codereview.stackexchange.com) – sjagr 2014-12-04 21:39:37