PHPStorm autocomplete for CakePHP custom helpers in view files

By Sinh Pham → Sunday 10 August 2014
https://3.bp.blogspot.com/-FOO7vXosvIA/U-hPD1CD5DI/AAAAAAAARc0/lD5FPJ4E_LY/s1600/09-results.png

Follow this post

Configure PhpStorm to Auto-complete CakePHP Models, Views, and Controllers
After playing around a bit today I finally figured out how to get PhpStorm to auto-complete methods for models and controllers. Here's what you need to do.
Removing Multiple Definitions


First, let's tackle the multiple definitions problem that we see below.
There are multiple places defining AppController. We need to remove the ones that are included in the following locations from our 'Directories' in the project's settings.
The two locations are:
$CAKEHOME/cake/console
$CAKEHOME/cake/tests
Next we need to mark the following file as plain text.
$CAKEHOME/cake/libs/controllers/app_controller.php
You should now see that PhpStorm is no longer complaining about multiple definitions. If it is you may want to check your plugins/components to see if they're mucking it up. If they are, just mark the file with the definition as plain text.
 We can now auto-complete on our models in the controller.
Lastly, we need to add magic properties to our models to define its relationships with other models. Basically, for each "belongs to" relationship defined in the model's file you need to add the magic property comment.
We can now auto-complete these relationships.
To get auto-completion working in views we need to include a file created by junichi11 over at GitHub.
Download this file and save it in a directory somewhere outside of your current project. I did this so I could use the same file on multiple projects.

Open a view file and add the following variable definition.
You should now be able to auto-complete helpers in your view!
Add the following to your app_controller.php file and this will add component auto-completion.

https://2.bp.blogspot.com/-GAu-OWes7EE/T6kmW76SL5I/AAAAAAAAMdY/aoIzBRamSxE/s1600/multiple_definitions1.png




https://4.bp.blogspot.com/-awXdS37tu3w/T6ksKUQevhI/AAAAAAAAMds/Mlasb9L9lYM/s1600/multiple_definitions2.png





Auto-completion should now work for the controller. However, it's still not working correctly on our model.

  
Adding the Model

To fix the model we need to add a magic property to the class.

 /** 
 *@property ModelName $ModelName 
 */ 

Here's an example from the controller we've been working in.

Defining Model Relationships

Setting Up Helper Auto-completion in Views

Now add that directory to your current project.
 /** 
 *@var $this View 
 */ 
  

Core Component Auto-Completion

 /** 
  * CakePHP Component & Model Code Completion 
  * @author junichi11 
  * 
  * ==============================================  
  * CakePHP Core Components 
  * ==============================================  
  * @property AuthComponent $Auth 
  * @property AclComponent $Acl 
  * @property CookieComponent $Cookie 
  * @property EmailComponent $Email 
  * @property RequestHandlerComponent $RequestHandler 
  * @property SecurityComponent $Security 
  * @property SessionComponent $Session 
  */ 

hwarf.com

Free Apple App

I'm Free Apple App. A full time web designer. I enjoy to make modern template. I love create blogger template and write about web design, blogger. Now I'm working with http://free-apple-apps.blogspot.com/. You can contact me.

No Comment to " PHPStorm autocomplete for CakePHP custom helpers in view files "