Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm autocomplete for CakePHP custom helpers in view files

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.

like image 511
trante Avatar asked Jun 03 '13 20:06

trante


2 Answers

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)

like image 160
trante Avatar answered Oct 17 '22 17:10

trante


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.

like image 2
jimiyash Avatar answered Oct 17 '22 18:10

jimiyash