相关疑难解决方法(0)

Symfony2 和 MVC - 扩展控制器是一个好的实践吗?

我有一个简单但也许愚蠢的问题。

使用 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 模式来说通常会好吗?

php model-view-controller controller symfony symfony-2.4

2
推荐指数
1
解决办法
1947
查看次数