Autocomplete for custom helpers in CakePHP application's 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 $MyelegantHelper Myelegant
     */

Notes: Autocomplete successfully works for core helpers inside view (ctp) files. But not for custom helpers.

4 comments
Comment actions Permalink

Hi there,

First of all (FYI): I'm not using CakePHP myself.


In any case:

1) @property $MyelegantHelper Myelegant --- the correct way is to have type BEFORE property name, not other way around as you have here. It should be @property Myelegant $MyelegantHelper

2) Where you defining such @property tags ? @property can only be located in PHPDoc comment that belongs to a class. In all other places it will be ignored.

3) What is View? -- As I understand it is standard CakePHP class. If so -- you better do the same what you do with controller -- declare your own (class MyView extends View ...), add your custom @property tags before it and use it instead.


P.S.
Just check the very last comment in the link you have provided -- I think it addresses the same issue:

You also can create an empty class in View folder:

    /**
     * @property MyFirstHelper $MyFirst
     * @property MySecondHelper $MySecond
     */
    class HintView extends AppView {}

Later in your views:

    /* @var $this HintView */

By this way you can get autocompletion in views with your own helpers.

0
Comment actions Permalink

1) Sorry for the typo. It should be like you mentioned.
* @property MyelegantHelper $Myelegant

But adding property doesn't work.
$Myelegant->
doesn't autocomplete.

But when I do this:
* @var $Myelegant MyelegantHelper
This gives successfully for
$Myelegant->

This works also:
* @var $this View

But CakePHP needs helpers should be used like this:
$this->Myelegant->myfunction();

So is it possible to reach Myelegant class from this word?

2) Views are not PHP classes, they are like templates that includes PHP, HTML codes inside.
Although they don't have "class" word, some autocompletion features works that I mentioned above.

3) That last comment in blog states for the helpers that are used inside custom Views. I will use core View.
So I don't want to change core View file or inherit all my Views from an empty View class.


0
Comment actions Permalink

*) You cannot attach @property to already existing class from some another location. It can ONLY be declared in PHPDoc comment just BEFORE that class.

*) You cannot typehint with PHPDoc sub-property of a class, I mean this will NOT work under any cirmustances: /** @var $this->Myelegant MyelegantHelper */

It has to be done either in class itself (real property/field declaration) or via @property tag in PHPDoc comment that belongs to that class ONLY.

*)

That last comment in blog states for the helpers that are used inside custom Views. I will use core View

You are using core View but with your OWN CUSTOM helpers. You have to declare them somehow, so IDE knows about them (that they are available in this class).

http://book.cakephp.org/2.0/en/views.html#creating-your-own-view-classes
You can create your own view class and use it -- I personally see nothing wrong with it at all -- you are not editing core classes here. Hey ... it does not even necessary to be actually used in your code -- you can just create such file and reference it -- it will be for IDE only.

0
Comment actions Permalink

It worked like a charm.
Thank you for great support :)

0

Please sign in to leave a comment.