问题
I use PhpStorm 6.0.2 and CakePHP 2.3.
In my controller file I define this and get autocomplete for my custom components:
/**
* @property MysuperComponent $Mysuper
*/
Regarding to this, in my view files I define this to reach Cake's core helpers and this works:
/**
* @var $this View
*/
I need autocomplete for custom helpers inside my views. I tried this but didn't work:
/**
* @property Myelegant $MyelegantHelper
*/
When I do this, this works partially:
/**
* @var $Myelegant MyelegantHelper
*/
I get this $Myelegant->
autocomplete. But it isn't adequate. I need autocomplete like this: $this->Myelegant->
Notes: Autocomplete successfully works for core helpers inside view (ctp) files. But not for custom helpers.
回答1:
Add new file /app/View/HintView.php
Add your custom helpers' names on PHPDoc.
<?php
App::uses('View', 'View');
/**
* @property MyelegantHelper $Myelegant
* */
class HintView extends View {
}
Inside your layout files or View files (ctp files) add this code on top
/**
* @var $this HintView
*/
Now inside your views you can see like this:
$this->MyElegant
->Blocks
->Cache
->Form
$this->MyElegant->somefunction()
anotherfunction()
oldfunction()
You don't have to extend your Views from HintView. It is only for PhpStorm's autocomplete.
(Note that you can make it faster with creating shortcuts to codes. For example goto Settins / IDE Settings / Live Templates. Add new template. For example "myeleg" for "$this->MyElegant->
" So when you write "myeleg" and press Tab key it will write the class name automatically)
回答2:
Have you tried looking at this article:
http://blog.hwarf.com/2011/08/configure-phpstorm-to-auto-complete.html
Look at the section "Setting Up Helper Auto-completion in Views". Hopefully this helps.
回答3:
I know this is an old post, but came across this having the same issue. Solved it this way:
For me, my custom helper is called StatusHelper, so needed the @property as follows:
App::uses('Helper', 'View');
/**
* @property StatusHelper $Status
* */
class StatusHelper extends AppHelper {
Then in the view .ctp file, I just needed the following at the top:
<?php /* @var $this View|StatusHelper */ ?>
Now the autocomplete works for my PHPstorm in that view for both core View vars as well as whatever ever methods are in my helper.. Happy days
Using Cake 2.5 - PHPstorm 10. Hope this helps someone else out there...
回答4:
Is Easy, Test in CakePHP 3.x to PHPStrom, supports namespace.
Add in to file views.ctp type PHPDoc
<?php /** @var $this Cake\View\View */ ?>
来源:https://stackoverflow.com/questions/16905153/phpstorm-autocomplete-for-cakephp-custom-helpers-in-view-files