Symfony2 and MVC - Is an expansion controller a good practice?

I have a simple and possibly stupid question.

Using the Symfony2 framework, I often work on extending controllers, as shown below (of course, it depends on the type of work):

    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();
     //...
    }

Is this a good practice?

Surfing the Internet, I found many articles, but it’s still not so clear to me.

After all, if it works fine in Symfony2, would it be good at all for the MVC pattern?

+2
source share
1 answer

Symfony MVC. Symfony - - . .

, .

, .

+4

Source: https://habr.com/ru/post/1609583/


All Articles