PHPStorm autocomplete for CakePHP custom helpers in view files

余生长醉 提交于 2019-12-04 04:58:23

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)

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.

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...

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  */  ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!