We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Yii 1.1: Configuring PhpStorm IDE for Yii


Code completion

  1. Exclude yiilite.php from index:
    • File → Settings → IDE Settings → File Types.
    • yiilite.php to Ignore files and folders.
  2. Exclude not used directories, specify resources.
    • File → Settings → Project settings → Directories.
    • Mark framework/cli/views, protected/runtime and assets as excluded.
    • Mark website root as resource root.
  3. Specify path to your PHP.
    • File → Settings → Project settings → PHP → PHP Home.
  4. If your project uses common Yii framework folder you need to include it.
    • File → Settings → Project settings → PHP → PHP Home → Add.
    • Specify a path to framework directory.
  5. If you are writing unit tests you can include PHPUnit to get code completion:
    • File → Settings → Project settings → PHP → PHP Home → Add.
    • Specify a path to PHPUnit.
  • Complete code: Ctrl+Space.
  • Show method arguments: Ctrl+Q.

Enhanced code navigation

In order to be able to get from render or renderPartial to the view, from widget to widget class, from relations to model classes you need to install additional plugin called YiiStorm.


You should install PHPUnit to run unit tests.

  1. PHPUnit.
    • Follow official PHPUnit installation guide.
    • In your IDE: Run → Edit configurations.
    • Press "+".
    • Name: anything.
    • Test: depending on what do you want to test select an appropriate option. Specify path.
    • Use XML configuration file: specifying path to phpunit.xml. Often it's path_to_your_webroot/protected/tests/phpunit.xml.
  • To run tests use SHIFT+F10.

Total 20 comments

#15817 report it
cornernote at 2013/12/19 08:06am

I released a gii generator that will generate phpDoc code for all your models - gii-modeldoc-generator

It really helps with phpStorm's autocomplete.

#15194 report it
johnsnails at 2013/10/16 06:26am
Re: Re: johnsnails at 2013/06/28 07:29am

Hi Luke,

I feel terrible that I only just now noticed you wrote back to me.

Much appreciated, thank you for clarifying that.


#15187 report it
DrMabuse at 2013/10/16 04:04am
Yii storm

v0.9.4b - 29.09.13 several fixes with autocompleter

#15170 report it
mazx at 2013/10/14 07:49pm

Yiistorm 0.9b create phpdoc inside new "View" after $this->render('view') autocomplete

#14667 report it
clod at 2013/09/02 10:30am

I suggest to try Codelobster PHP Edition

This IDE has special plug-in for Yii autocomplete and so on.

#14229 report it
Luke Jurgs at 2013/07/28 09:34pm
Re: johnsnails at 2013/06/28 07:29am

Hi John,

PHPStorm uses any @var phpdoc declaration as a type hint. It doesn't understand how the view is actually being rendered, since it only really has a lexical/syntactic parser and whatever magic they bake into "intellisense", it isn't a fully fledged interpreter.

So in your case you would have to hint at what $num is. E.g:

/** @var $num int */
#13822 report it
johnsnails at 2013/06/28 07:29am
Re: Luke Jurgs at 2011/10/28 09:23am ^^

Hi Luke,

My site/index.php file has this at the top.

/* @var $this SiteController */

But I cannot get intellisense on a variable passed from the actionIndex like so.


<?php echo $num; ?>



public function actionIndex()
        $num = 23;
        // renders the view file 'protected/views/site/index.php'
        // using the default layout 'protected/views/layouts/main.php'
        $this->render('index', array('num' => $num));


Is this what you are talking about working? Any ideas? I have followed the other steps in this post.

#12767 report it
Boaz at 2013/04/11 02:46am
Letting the IDE know about behavior-provided methods?


Is there a way to let the IDE know automatically the methods provided by behaviors attached to a model, as defined in its 'behaviors()' method? I emphasize 'automatically' as I know I can use a doc block above the model class, with a comment such as:

* @method generateUniqueSlug()

I want to avoid needing to manually write (and maintain) all those methods.

If there's no such solution, does anyone know about an open bug/feature-request on this?


#9855 report it
JFReyes at 2012/09/15 03:27pm
PhpStorm 5 is out with "Yii integration"

I'm no expert so does anyone know how to take advantage of it (besides what's described here)? Thanks in advance.

#9589 report it
balrok at 2012/08/26 11:35am
Autoadd @var

Hello, for a bigger project I needed the @var in all my models from database so I wrote a yii command to do this automatically. I've posted it here. Please try it carefully it worked with my codebase quite well but could go rampage when the code is strangely formatted/structured.

#9193 report it
KingYes at 2012/07/27 04:12am

Hey all, If you want to have auto complete for the component's attributes and methods, Just use with that code:

In your main index.php, just include the YiiBase.php (not yii.php).




And just add this code after $yii include line:

class Yii extends YiiBase
     * @static
     * @return CWebApplication
    public static function app()
        return parent::app();

and now you can use with Yii::app()->user->id and all what you need :)

Have fun :)

#8486 report it
Stephen51 at 2012/06/06 06:38pm
Path Mappings

If there is a symbolic link in one of your libraries, you will need to tell PHPStorm about the symbolic link through a path mapping. For example, XAMPP uses the following symbolic links:

/Application/XAMPP stephen$ ls -lh
total 32
drwxr-xr-x   3 admin  admin   102B Feb 27  2010 XAMPP Control.app
lrwxr-xr-x   1 admin  admin    18B Feb 27  2010 cgi-bin -> xamppfiles/cgi-bin
lrwxr-xr-x   1 admin  admin    14B Feb 27  2010 etc -> xamppfiles/etc
lrwxr-xr-x   1 admin  admin    17B Feb 27  2010 htdocs -> xamppfiles/htdocs
lrwxr-xr-x   1 admin  admin    15B Feb 27  2010 logs -> xamppfiles/logs
drwxr-xr-x@ 23 root   admin   782B Feb 27  2010 xamppfiles

To include the Yii framework in your project,

1) Go to Preferences>Project Settings>PHP Home and add a PHP include path "/Applications/XAMPP/htdocs/yii".

2) Go to Preferences>Project Settings>PHP>Server and enable path mapping for the server. Create the following path mapping: "/Applications/XAMPP/htdocs/yii" -> "/Applications/XAMPP/xamppfiles/htdocs/yii".

#8078 report it
SebK at 2012/05/08 03:10pm

Nice guide! I finally have all the autocompletion working properly.

I attempted following boaz's guide for the debugging connection but must have gone wrong somewhere. If found a guide by the makers which requires less configuration and worked immediately (after setting the xdebug.remote_enable = 1);

Link to guide

edit: now both debugging variants work. Happy days!

#7875 report it
pligor at 2012/04/24 08:40am

How could I make php storm aware of the yii components loaded? So that lines like this:


have auto complete for the component's attributes and methods? :)

I have seen it happen in netbeans..

#7446 report it
Boaz at 2012/03/23 02:22am
Making PhpStorm know variable types even more

@codescope: also see comment http://www.yiiframework.com/wiki/92/configuring-phpstorm-ide-for-yii/#c5646 for info on using @var tag to make the IDE know the variable type. This is still highly needed or used in Yii code.

#7440 report it
codescope at 2012/03/22 09:32pm
instead of adding yii in php include path add in project settings->directories

I had some issues with method showing up as not existing in current class although they were in parent class . I went to phpstorm forums and they linked back here with some additional checks to perform. I did as mentioned in this wiki and also added yii framework in settings->project settings->directories instead of adding it in external libraries and it is perfectly configured now.

#7100 report it
Boaz at 2012/02/23 03:11pm
Debugging settings

I think its good to have a section of "debugging" in this wiki article. I've sketched below a draft for its content. Its a big topic which probably deserves a separate wiki. Nevertheless, here it is:

Debugging on localhost

Many developers have a working web server on the same machine in which they develop. The following instructions are suitable for a simple use case where a developer run his web app on the same machine (with URL like mysite.local) and where the IDE edits the code in the doc root directly. This article is not intended to be a complete debugging PHP web app tutorial but just to hint the reader in the places to edit with basic values to use as configuring the IDE and the environment for debugging might require more work and configuration. The Internet have lots of useful tutorials these days for PHP debugging (for example (a bit old but still useful): http://www.rymland.org/en/blogs/boaz/3_mar_08/using-pdt-xdebug-debugging-drupal-projects).


This assumes that you'll use the popular xDebug PHP extension for the server side debugger component (the client side is PHP Storm itself). Make sure to install it in your PHP environment where you'll do the debugging (localhost). Please refer to xDebug documentation for information about this. Don't forget to edit xdebug.ini in your PHP's configuration to have "xdebug.remote_enable=1"

Configuring web server for project

First, we're gonna need to tell the IDE about the web server it needs to talk to: File -> Settings -> Project settings -> PHP -> Servers. Click (+) -> Name: give a name (example: mysite localhost); Host: hostname used to access the web app from the browser (example: mysite.local is a commonly used convention); port: probably leave on 80; Debugger: xdebug Click Apply, then Ok.

Menu bar: Run -> Edit configurations. We're gonna create a new configuration: Click (+) -> PHP web application: Name: your preferred name (example: mysite localhost); Server: choose the server created in above steps in this drop down selector; Start URL: leave on "/"; Browser: choose your browser (you might need to configure this in advance in Settings -> IDE Settings -> Web Browsers); Other parameters - to your liking. I leave the other checkboxes unchecked. Click Apply, then Ok.

Starting a debug session

From the tool bar, click on dropdown which now shows the name of the debug configuration you've created in previous step. Then click on the "Debug " button which is typically the second button to the right of the configurations drop down you've just selected. A debug session will be opened:

  • A browser will be launched on the needed URL.
  • "Debug" window tool will pop open.
  • The browser will now proceed as expected based on the URL given in the debug configuration (if you left it as "/" as described above then the root of the web app will open int he browser).
  • Now, try to enter breakpoints where needed and use the browser to navigate the site and reach the scenario you want to debug.
  • Enjoy debugging, inspecting the variables, the call stack and the extremely useful flow control buttons, enabling you to see exactly how the application behaves internally in terms of who calls what and when, and what variables stack exists and follows those steps.
#6716 report it
outrightmental at 2012/01/31 12:48pm
Notes on Configuring PhpStorm Mac OS X for Yii

In PhpStorm for Mac OS X, there are some differences:

  1. Exclude yiilite.php from index:
    • PhpStorm → Preferences → [IDE Settings] File Types.
    • Append yiilite.php to Ignore files and folders field.
  2. Exclude not used directories, specify resources.
    • PhpStorm → Preferences → [Project Settings] Directories.
    • Mark framework/cli/views, protected/runtime and assets as excluded.
    • Mark website root as resource root.
  3. Specify path to your PHP.
    • Set the Interpreter path. E.g. /Applications/MAMP/bin/php/php5.3.6/bin
    • PhpStorm → Preferences → [Project Settings] PHP.
  4. If your project uses common Yii framework folder you need to include it.
    • PhpStorm → Preferences → [Project Settings] PHP → Add.
    • Specify a path to framework directory.
  5. If you are writing unit tests you can include PHPUnit to get code completion:
    • PhpStorm → Preferences → [Project Settings] PHP → Add.
    • Specify a path to PHPUnit.
#6065 report it
grigori at 2011/12/09 05:17am
resolving "multiple declarations" when yii is in the include path

There is no "Project settings → PHP → PHP Home" now, you can add yii folder as include path in "Project settings → PHP".

It's not possible to exclude the cli/views folder when yii is "connected" as a folder in the include path. All you can do to avoid "multiple declarations" problems with SiteController and Controller classes is to mark files [framework]/cli/views/webapp/protected/components/Controller.php and .../controllers/SiteController.php as plain text (right click on each file and select "Mark as Plain Text" in the context menu).

#5646 report it
Luke Jurgs at 2011/10/28 09:23am
Code completion in views

If you would like to be able to use code completion in your views you can add the comment:

 * @var $this ThisController

at the top, you can also add any variables assigned via the CController::render() function.

Leave a comment

Please to leave your comment.