Why doesn't magento autoload parent class

2019-05-06 19:33发布

I have a module which will use my controller over magento's by doing

<routers>
  <checkout>
    <args>
      <modules>
        <Some_Thing before="Mage_Checkout">Some_Thing</Some_Thing>
      </modules>
    </args>
  </checkout>
</routers>

In my class that extends the core class I have to explicitly require the class. Does anyone know why this is?

1条回答
在下西门庆
2楼-- · 2019-05-06 20:23

The Magento autoloader is a simple "replace underscores with slashes" algorithm. Because Zend Framework names its controllers differently, and because Magento uses parts of Zend and is inspired by Zend in others, its controllers are named with Zend conventions and placed in a controllers folder, meaning the standard autoload routine won't work.

It ends up controller classes are automatically included during Magento's routing process but NOT by the PHP auto loader. Instead, there's custom PHP code to handle this.

So, during routing, because you've told Magento to use your controllers instead of Magento's controller for a particular request, it's the only controller that gets included.

Best guess is the request for controller overrides caught the original developers off guard, and while they've been happy to jury rig a solution with routing, it hasn't been a priority to refactor the controller autoload code.

查看更多
登录 后发表回答