formatControllerName example

/** * Returns the template name of the current request instance. * The module, controller and action is gotten over the dispatcher instance of the Enlight_Controller_Front. * The template parts are imploded by "_" character. * * @return string */
    public function getTemplateName()
    {
        $request = $this->Action()->Request();
        $moduleName = $this->Front()->Dispatcher()->formatModuleName($request->getModuleName());
        $controllerName = $this->Front()->Dispatcher()->formatControllerName($request->getControllerName());
        $actionName = $this->Front()->Dispatcher()->formatActionName($request->getActionName());

        $parts = [$moduleName$controllerName$actionName];
        foreach ($parts as &$part) {
            $part = (string) preg_replace('#[A-Z]#', '_$0', $part);
            $part = trim($part, '_');
            $part = strtolower($part);
        }

        $templateName = implode(DIRECTORY_SEPARATOR, $parts) . '.tpl';

        
/** * Returns the template name. * * @return string */
    public function getTemplateName()
    {
        $request = $this->viewRenderer->Action()->Request();
        $dispatcher = $this->viewRenderer->Front()->Dispatcher();

        $moduleName = $dispatcher->formatModuleName($request->getModuleName());
        $controllerName = $dispatcher->formatControllerName($request->getControllerName());

        $controllerName = $this->get('events')->filter('Enlight_Controller_Plugin_ScriptRenderer_formatControllerName', $controllerName['subject' => $this]);

        $fileNames = (array) $request->getParam('file', $this->defaultFile);
        if (empty($fileNames)) {
            $fileNames = $request->getParam('f');
            $fileNames = explode('|', (string) $fileNames);
        }

        $templateNames = [];
        foreach ($fileNames as $fileName) {
            
$request->setControllerName($this->defaultController);
        }

        if (!$request->getModuleName()) {
            $request->setModuleName($this->defaultModule);
        }

        $module = $request->getModuleName();
        $this->curModule = $module;

        $moduleName = $this->formatModuleName($module);
        $controllerName = $this->formatControllerName($request->getControllerName());

        $class = ['Shopware', 'Controllers', $moduleName$controllerName];
        /** @var class-string $className */
        $className = implode(self::CLASS_NAMESPACE_SEPARATOR, $class);

        return $className;
    }

    /** * Returns the controller path of the given request class. * * @return object|string|null */
Home | Imprint | This part of the site doesn't use cookies.