Lynda MVC模式有很多优势,可实现单点控制,分离代码,快速开发,后期容易维护与扩展,代码架构清晰等等。 无 ?php// mvc pattern 单点控制// 简单的控制器 Cclass NumberController extends DefaultController{public $model = null;public function __const
Lynda
MVC模式有很多优势,可实现单点控制,分离代码,快速开发,后期容易维护与扩展,代码架构清晰等等。
model = NumberModel();
}
// V
public function view($value=0)
{
echo "The square of this number is: ",$this->model->square($value);
}
}
// 控制器的基类
class DefaultController
{
public function run($action = 'index', $id = 0)
{
if (!method_exists($this, $action)) {
$action = 'index';
}
return $this->$action($id);
}
// 简单输出模版
public function index()
{
$html = "";
for($i = 1; $i < 10; $i++)
{
$html .= sprintf('- %s









