【问题标题】:Phalcon DI phpStorm IDE not understand my codePhalcon DI phpStorm IDE 不理解我的代码
【发布时间】:2015-08-06 09:42:56
【问题描述】:

我在一个新项目中使用 phalcon,但我意识到 phpStorm 不了解我自己的注入器,例如:

   /**
     * Registering the helper component
     */
    $di->set('helper', function () {
        $helper = new \Frontend\Helpers\Common();
        return $helper;
    });

从我的控制器我可以做到这一点:

   $this->helper->getHelp();

它工作正常,但 IDE 不会自动完成我的代码。我当然可以这样做:

   /** @var \Frontend\Helpers\Common $helper  */
   $helper->...

在这种情况下,我可以看到所有方法,但是每次我需要使用帮助程序时,我都必须放置这个 cmets。

我想知道是否有办法使用自己的注入器并使 IDE 能够理解代码?

【问题讨论】:

    标签: php dependency-injection phalcon


    【解决方案1】:

    您可以使用此解决方法。

    services.php

    /**
     * Registering the helper component
     */
    $di->set('helper', function () {
        $helper = new \Frontend\Helpers\Common();
        return $helper;
    });
    

    AbstractController

    /**
     * My Abstract controller
     *
     * @property \Frontend\Helpers\Common helper
     */.
    class AbstractController extends \Phalcon\Mvc\Controller
    {
    
    }
    

    TestController

    class TestController extends AbstractController
    {
        public function indexAction()
        {
            $this->helper->...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-30
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 2022-05-15
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      相关资源
      最近更新 更多