我创建了自己的MVC的免费PHP当然,我进行对于想要在PHP中变得更好的少数人来说。
到目前为止,最好的方法是使用Command + Factory模式。
E.g.
interface ControllerCommand
{
public function execute($action);
}
在每个控制器:
class UserController implements ControllerCommand
{
public function execute($action)
{
if ($action == 'login')
{
$data['view_file'] = 'views/home.tpl.php';
}
else if ($action == 'edit_profile')
{
$data['view_file'] = 'views/profile.tpl.php';
$data['registration_status'] = $this->editProfile();
}
return $data;
}
}
从你的主前端控制器:
$data = ControllerCommandFactory::execute($action);
if (!is_null($data)) { extract($data); }
/* We know the view_file is safe, since we explicitly set it above. */
require $view_file;
的一点是,每Controllercommand类有一个执行功能和返回其视图和任何数据为此观点。
对于完整的MVC,您可以通过在theodore [at] phpexperts.pro上给我发邮件来访问开源应用程序。
所以你建议只返回控制器中的变量。然后在视图中说$ vars = new my_controller();然后使用适当的功能。这确实是一个很好的简单解决方案。 – Mike 2010-08-24 22:25:52