NetBeans IDE and Yii projects

You are viewing revision #38 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#35)next (#39) »

  1. 1. Code completion
  2. 2. Code templates
  3. 3. Testing
  4. 4. Debugging
  5. Got problems or questions?

This page is created to supply short directions and general tips for managing a Yii application in NetBeans IDE.

1. Code completion

To get context sensitive code completion, follow these steps:

  • If the Yii framework folder is not inside the project folder:
    • Open "File > Project properties > PHP Include Path" and add the Yii framework root path
  • Ignore yiilite.php to avoid doubled/missing documentation
    • Open "Tools > Options > Miscellaneous > Files"
    • Add to the front of "Files Ignored by the IDE" the file "^(yiilite\.php|CVS|SCCS|...."
    • Restart NetBeans
Usage:
  • Typing suggestions: Ctrl-Space
  • Show Function parameters: Ctrl-P
  • Comment your own code with PHPDoc style. Here's a good example.
  • Code completion in view files
    • Add the following PHPDoc statement at the head of the file to use code completion in view files. (you may add additional passed parameters as well)
/* @var $this PostController */
/* @var $model Post */
$this->getSomeProValue(); // possible with code completion
$model->author; // possible with code completion

2. Code templates

You can create code templates for commonly used/overridden function in Yii. For example, if you want to add an beforeSave() function in your model, by typing a shortcut you can automatically have the function template in place. There are additional shortcuts for common stuff like Yii::app(), Yii::t(), Yii::app()->user->checkAccess(), and more!

  • Download this template set to get started: http://fbe.am/hly (version 2). View all available commands in this printable cheat sheet.
  • Go to "Tools > Options > Editor > Code Templates"
  • Hit "Import", select the file, and choose "Code Templates"
    • You might get an error message "invalid zip file" if you are importing to a older/newer version of NetBeans. Open up the zip file, edit build.info, and set the correct path to Userdir.
Usage:
  • Type the shortcut and hit TAB
  • More info: NetBeans Docs
  • Example:
// typing: ybeforesave + TAB
// expands to:

/**
 * This method is invoked before saving a record (after validation, if any).
 * @return boolean whether the saving should be executed. Defaults to true.
 */
protected function beforeSave()
{
	
	return parent::beforeSave();
}

3. Testing

To run functional tests and unit tests in Yii, recommended is installing PHPUnit and SeleniumRC.

  • Install PHPUnit
  • Install SeleniumRC with one of these two methods:
    • Through NetBeans plugins (may be outdated):
    • Through the Selenium website:
  • Configure project options
    • Open "File > Project properties > Sources" and set "Test Folder" to [PROJECT ROOT]/protected/tests
    • Open "File > Project properties > PHPUnit" and set "Use Bootstrap" to [PROJECT ROOT]/protected/tests/bootstrap.php, and "Use XML Configuration" to [PROJECT ROOT]/protected/tests/phpunit.xml
Usage:
  • Test whole project: Alt+F6
  • Test single file: Shift-F6
  • Check code coverage (right click project > Code Coverage)

4. Debugging

  • Install Xdebug (usually already available in your installation):
  • Include the Xdebug extension for PHP:
    • In php.ini enable (by removing ; prefix) these settings:
      zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
         xdebug.remote_enable = 1
         xdebug.remote_handler = "dbgp"
         xdebug.remote_host = "localhost"
         xdebug.remote_port = 9000
Usage:
  • Debug project: Ctrl-F5
  • Use breakpoints, walk through running code, and watch variables and objects in real-time. :)
  • If you want to stop the debugger from pausing on the first line for every request, simply turn that "feature" off by clicking: Tools > Options > PHP > Debugging > Stop at First Line (uncheck)
5. Navigation, wizards, additional code completion

Install a special Yii plugin.

Got problems or questions?

Do NOT post a comment on this wiki page, but go to the forums: http://www.yiiframework.com/forum/index.php?/topic/11735-netbeans-ide-and-test-driven-development/

65 0
66 followers
Viewed: 252 036 times
Version: Unknown (update)
Category: Tutorials
Written by: marcovtwout
Last updated by: marcovtwout
Created on: Sep 21, 2010
Last updated: 9 years ago
Update Article

Revisions

View all history

Related Articles