我有一个简单但也许愚蠢的问题。
使用 Symfony2 PHP 框架,我经常扩展控制器,如下所示(当然这取决于工作类型):
class MainController extends Controller{
private $locale = array();
protected function Locale() {
$em = $this->getDoctrine()
->getManager();
$this->locale = $em->getRepository('CommonLanguageBundle:Language')
->findBy(
array('code' => $this->getRequest()
->getLocale()
)
);
// \Doctrine\Common\Util\Debug::dump($this->locale);
return $this->locale[0];
}
//..
}
class StoreController extends MainController{
function a_method() {
$data = $this->Locale()->getId();
//...
}
}
class DefaultController extends StoreController {
$data = $this->Locale()->getId();
//...
}
Run Code Online (Sandbox Code Playgroud)
这是一个好的做法吗?
在网上冲浪我发现了很多文章,但对我来说仍然不太清楚。
最后,如果它在 Symfony2 中运行良好,那么它对于 MVC 模式来说通常会好吗?