开发者

Code completion for CakePHP in IDE

开发者 https://www.devze.com 2023-04-01 01:56 出处:网络
Someone recommended I \"use code completion\" and I realized that while my IDE has code completion, it doesn\'t recognize the large majority of methods and variables inherited from CakePHP\'s framewor

Someone recommended I "use code completion" and I realized that while my IDE has code completion, it doesn't recognize the large majority of methods and variables inherited from CakePHP's framework, most notably the Helper methods for views. I'm using PhpED but it seems like it's code completion is supposed to work just as it does in eclipse and other editors.

I followed this advice to no avail; I created a helpers.php file with definitions of all the helpers and included it in the project but 开发者_高级运维the code completion still doesn't work with the Helpers.

I think part of the problem is Mark Story's post is from an old version of cake (I am on Cake 1.3) so I updated the definitions of the Helpers to look like this:

$this->Form = new FormHelper();

But there's still no code completion for any of the views. Is there any way to make this work? In addition to the Helpers I'd really like completion for functions like Model->find() but those don't work either.


as you might have noticed from several working code completion scripts out there you always need to put them into scope. meaning: you need to wrap them with the class they should be used in. at least for components and models etc. for helpers this is more difficult since they would be in the View scope which is not directly available/visible for IDEs in the views/layouts. i use the app helper as scope. works for me anyway. more correct would be View class.

either way there is probably not a foolproof method for helpers. most IDE should pick it up, though.

e.g. mine (for phpdesigner): http://www.dereuromark.de/tag/code-completion/

but the others are similar.


For PhpED you have to do the following to enable Autocompletion for $this.

Lets say you want to use $this in a Controller for something like this

$this->Project->Country->getCountryName($countryId)

First add this PhpDoc tag before the class definition

/**
* @property-read Project $Project
*/
class ProjectsController....

Now typing $this->Project should work as intended. Next up is the Project model class.

In here add the following code, again before the class definition

/**
* @property-read Country $Country
*/
class Project extends AppModel

Now $this->Project->Country->getCountryName($countryId) works. The method is not 100% as i would like it, as PhpEDs Autocompletion sorts alphabetically, so any class starting with A or B will be shown before the methods of the Country mode.


This is not an answer to your question.

I would recommend gedit, with the word completion plugin. While not an IDE-level "Code Completion" plugin, it does an awesome job at picking up words from your source files and using those to populate its word list. It "just works" for nearly any framework, any language, because of that organic approach to building the word list. (Shameless plug to my blog, with lots of tips and tricks for how gedit can be the best editor out there: http://davidsouther.com/2011/08/gedit-tips-tricks/)

0

精彩评论

暂无评论...
验证码 换一张
取 消