1

CustomControllerAction.php で $this->moduleName の値を取得しようとしていますが、モジュール javascript と一般の間で値が異なります。

for: http://myip.com/username/general エコー結果は「general」

ただし、 http://myip.com/username/javascript エコー結果は「デフォルト」ですが、「javascript」にする必要があることはわかっています。

モジュール javascript がそのモジュール名を取得できなかったのはなぜですか?

ビューのプレゼンテーションには、Zend Framework のモジュール構造と Smarty を使用します。

ありがとうございました。

これは私のコードです:

/modules/javascript/controlles/IndexController.php

<?php
class Javascript_IndexController extends modules_CustomControllerAction
{
    public function init()
    {
        /* Initialize action controller here */
        parent::init();
        $view = new EZ_View_SmartyJS($this->config->smarty->toArray());     
        $view->setScriptPath(APPLICATION_PATH.'/modules/javascript/views/theme_classic/js/');       
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
            'ViewRenderer'
        );
        $viewRenderer->setView($view);
        $viewRenderer->setViewSuffix($this->config->smarty->javascriptSuffix);
        $this->_helper->layout->disableLayout();
        $this->getResponse()
            ->setHeader('Content-Type', 'text/javascript');

        $this->params = $this->getRequest()->getParams();
        $this->view->params = $this->params;

    }
}
?>

/modules/general/controlles/IndexController.php

<?php
class General_IndexController extends modules_CustomControllerAction{
    public function init()
    {
        parent::init();
        // initialize smarty view
        $view = new EZ_View_Smarty($this->config->smarty->toArray());
        $view->setScriptPath(APPLICATION_PATH.'/modules/general/views/theme_classic/scripts/');
        // setup viewRenderer with suffix and view
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setViewSuffix('tpl');
        $viewRenderer->setView($view);

        $layout = Zend_Layout::getMvcInstance();
        $layout->setViewSuffix('tpl');

        /**
         * Set inflector for Zend_Layout
         */
        $inflector = new Zend_Filter_Inflector(':script.:suffix');
        $inflector->addRules(array(':script' => array('Word_CamelCaseToDash', 'StringToLower'),
                                                      'suffix'  => 'tpl'));
         // Initialise Zend_Layout's MVC helpers
        $theme = 'theme_classic';
        Zend_Layout::startMvc(array('layoutPath' => APPLICATION_PATH . '/modules/themes/'.$theme.'/layout/',
                                    'view' => $view,
                                    'contentKey' => 'general',
                                    'inflector' => $inflector));
    }
}
?>

/アプリケーション/Bootstrap.php

<?php
    protected function _initRoutes()
    {
        $this->bootstrap('frontcontroller');
        $front = $this->getResource('frontcontroller');

        $router = $front->getRouter();

        $router->addRoute('root', new Zend_Controller_Router_Route(
            '/',
            array(
                'module' => 'home',
                'controller' => 'index',
                'action' => 'index'
            )
        ));
        $router->addRoute('javascript', new Zend_Controller_Router_Route(
            ':username/javascript/:action/*',
            array(
                'controller' => 'index'
            )
        )); 

        $router->addRoute('default', new Zend_Controller_Router_Route(
            ':username/:module/:action/*',
            array(
                'controller' => 'index'
            )
        )); 


        $router->addRoute('index', new Zend_Controller_Router_Route(
            ':username/:module',
            array(
                'controller' => 'index',
                'action' => 'index'
            )
        ));     
        return $router;
    }
?>

/application/modules/CustomControllerAction.php

<?php
    public function init(){
        $controller = Zend_Controller_Front::getInstance();
        $this->moduleName = $controller->getRequest()->getModuleName();
        $this->controllerName = $controller->getRequest()->getControllerName();
        $this->actionName = $controller->getRequest()->getActionName();
        $this->userName = $controller->getRequest()->getParam('username');

        echo moduleName; //<------------------test result
    }
?>
4

0 に答える 0