wonderfan / magento

Magento Theme and Module Development
http://www.wonderfan.github.io
1 stars 2 forks source link

The Front controller #14

Closed wonderfan closed 9 years ago

wonderfan commented 9 years ago

The application object is associated with front controller class

wonderfan commented 9 years ago

The main characteristics of front controller class:

wonderfan commented 9 years ago

The routers are declared in the xml by const XML_STORE_ROUTERS_PATH = 'web/routers';

wonderfan commented 9 years ago

The match process:

wonderfan commented 9 years ago

How to find the controller class:

    public function getControllerFileName($realModule, $controller)
    {
        $parts = explode('_', $realModule);
        $realModule = implode('_', array_splice($parts, 0, 2));
        $file = Mage::getModuleDir('controllers', $realModule);
        if (count($parts)) {
            $file .= DS . implode(DS, $parts);
        }
        $file .= DS.uc_words($controller, DS).'Controller.php';
        return $file;
    }
wonderfan commented 9 years ago

The path is module path plus controller directory plus TestController.php

wonderfan commented 9 years ago
$controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
wonderfan commented 9 years ago
    public static function getControllerInstance($class, $request, $response, array $invokeArgs = array())
    {
        return new $class($request, $response, $invokeArgs);
    }