使用 PHPDoc @property 加载模型以进行自动完成

发布于 2024-09-18 21:34:09 字数 571 浏览 8 评论 0原文

我正在使用 PHP 的 Codeigniter 框架。我想知道是否有一种方法可以使用 PHPDoc @property 在模型中加载方法以进行自动完成。

我的意思是......

class abc_controller extends Controller {

  /**
   * @property Model1
   */
  function func() {
     $this->load->model("Model1"); // I am loading the model here

     $result = $this->Model1->getIds(); 
     // When I type Model1 in the statement above, it should popup 
     // an autocompletion box populated with all the methods of Model1
  }
}

我在使用 Cakephp 时使用 NetBeans 做了类似的事情。我想知道 CodeIgniter 是否也可以这样做/

问候

I am using Codeigniter framework for PHP. I was wondering if there is a way to load methods in a Model for autocompletion using PHPDoc @property.

What I mean is ....

class abc_controller extends Controller {

  /**
   * @property Model1
   */
  function func() {
     $this->load->model("Model1"); // I am loading the model here

     $result = $this->Model1->getIds(); 
     // When I type Model1 in the statement above, it should popup 
     // an autocompletion box populated with all the methods of Model1
  }
}

I did something like this using NetBeans while working on Cakephp. I was wondering if such a thing is possible for CodeIgniter as well/

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2024-09-25 21:34:09

您需要向您的 phpdoc 类添加属性。观看此视频 http://netbeans.org/kb/ docs/php/class-property-variables-screencast.html

<?php

/**
 * blah blah balh
 *
 * @property Model1 Model1
 * @property <type> <name>
 */
class abc_controller extends Controller {

    /**
     * blah blah blah
     */
    function func() {
        $this->load->model("Model1"); // I am loading the model here

        $result = $this->Model1->getIds();
        // When I type Model1 in the statement above, it should popup
        // an autocompletion box populated with all the methods of Model1
    }

}

?>

或者,如果您从具有混合返回类型的函数中获取值,则需要像这样:

 function func(){
        $myObj =  $this->getMixedType();
        /* @var $myObj TypeOfMyObject */

        //  The vdoc has to be below the function call, otherwise the latest return type will be used
        //  Shortcut for generating vdoc is "vdoc" + tab
        //  For example if you have vdoc above the function call and function 
        //  returns Type1, then your object will have autocomplete for Type1.
    }

You need to add property to your class phpdoc. Check this video out http://netbeans.org/kb/docs/php/class-property-variables-screencast.html

<?php

/**
 * blah blah balh
 *
 * @property Model1 Model1
 * @property <type> <name>
 */
class abc_controller extends Controller {

    /**
     * blah blah blah
     */
    function func() {
        $this->load->model("Model1"); // I am loading the model here

        $result = $this->Model1->getIds();
        // When I type Model1 in the statement above, it should popup
        // an autocompletion box populated with all the methods of Model1
    }

}

?>

Or if you are getting a value from a function with a mixed return type you need to to it like this:

 function func(){
        $myObj =  $this->getMixedType();
        /* @var $myObj TypeOfMyObject */

        //  The vdoc has to be below the function call, otherwise the latest return type will be used
        //  Shortcut for generating vdoc is "vdoc" + tab
        //  For example if you have vdoc above the function call and function 
        //  returns Type1, then your object will have autocomplete for Type1.
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文