blob: 5f1d0297bcd140dc76ca6be94ffc9724b1ff6286 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
-->
<html>
<head>
<title>NetBeans IDE for PHP Editor</title>
<meta name="KEYWORDS" content="NETBEANS, PHP, editor">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="DESCRIPTION" content="NetBeans, PHP editor" >
<link rel="stylesheet" type="text/css" href="../../../netbeans.css" media="screen"></head>
<body>
<h1>NetBeans IDE for PHP Editor: Brief Overview</h1>
<p>This document is a brief overview of the main features of the NetBeans IDE PHP Editor.</p>
<p><strong>Contents</strong></p>
<img src="../../../images_www/articles/72/netbeans-stamp-74-73-72.png" class="stamp" alt="Content on this page applies to NetBeans IDE 7.2, 7.3 and 7.4" title="Content on this page applies to the NetBeans IDE 7.2, 7.3 and 7.4" >
<ul>
<li><a href="#gettingReady">Getting Ready</a></li>
<li><a href="#editorLayout">The NetBeans IDE for PHP Editor Layout</a></li>
<li><a href="#SyntaxHighlighting">Syntax Highlighting</a></li>
<li><a href="#goToDeclaration">Go To Declaration</a></li>
<li><a href="#Navigator">Navigator</a></li>
<li><a href="#CodeFolding">Code Folding</a></li>
<li><a href="#SmartIndent">Smart Indent</a></li>
<li><a href="#Formatting">Formatting</a></li>
<li><a href="#BracketCompletion">Bracket Completion</a></li>
<li><a href="#instant-rename">Rename Refactoring and Instant Rename</a></li>
<li><a href="#CodeCompletion">Code Completion</a>
<ul>
<li><a href="#snippets">Snippets</a></li>
<li><a href="#contextSensitiveProposals">Context-Sensitive Proposals</a></li>
<li><a href="#abbreviations">Code Templates and Abbreviations</a></li>
<li><a href="#cc-constructors">Code Completion in Constructors</a></li>
<li><a href="#cc-sql">SQL Code Completion</a></li>
<li><a href="#cc-namespaces">PHP 5.3 Namespaces</a></li>
<li><a href="#cc-overridden-methods">Overridden and Implemented Methods</a></li>
<li><a href="#clever-catch-cc">Clever Try/Catch Code Completion</a></li>
</ul>
</li>
<li><a href="#php54">PHP 5.4 Support</a></li>
<li><a href="#rectangular">Rectangular Selection</a></li>
<li><a href="#phpdoc">ApiGen Support</a></li>
<li><a href="#code-generators">Code Generators</a>
<ul>
<li><a href="#generate-constructors">Constructors</a></li>
<li><a href="#generate-getters-setters">Getters and Setters</a></li>
<li><a href="#generate-overriden-methods">Overridden and Implemented Methods</a></li>
</ul></li>
<li><a href="#vartyp-cmnt">Defining Variable Type in Comments</a></li>
<li><a href="#ParameterHints">Parameter Hints</a></li>
<li><a href="#errorMessages">Error Messages</a></li>
<li><a href="#phpunit">PHPUnit and Selenium tests</a></li>
<li><a href="#spellchecker">Spellchecker</a></li>
<li><a href="#symfony">Symfony, Symfony2, and Zend Framework Support</a></li>
<li><a href="#smarty"> Smarty Support</a></li>
<li><a href="#doctrine2">Doctrine2 Support</a></li>
</ul>
<p><b>To follow this tutorial, you need the following software and resources.</b></p>
<table>
<tbody>
<tr>
<th class="tblheader" scope="col">Software or Resource</th>
<th class="tblheader" scope="col">Version Required</th>
</tr>
<tr>
<td class="tbltd1"><a target="_blank" href="https://netbeans.org/downloads/index.html">NetBeans IDE</a></td>
<td class="tbltd1">PHP download bundle</td>
</tr>
<tr>
<td class="tbltd1">A PHP engine</td>
<td class="tbltd1">Version 5
</tr>
<tr>
<td class="tbltd1">A web server</td>
<td><a target="_blank" href="http://httpd.apache.org/download.cgi">Apache HTTP Server 2.2</a> is recommended.<br></td>
</tr>
<tr>
<td class="tbltd1">A PHP debugger</td>
<td><a target="_blank" href="http://www.xdebug.org">XDebug 2.0 or later</a></td>
</tr>
</tbody>
</table>
<h2><a name="gettingReady"></a>Getting Ready</h2>
<p>To successfully develop and deploy PHP applications in the NetBeans IDE
for PHP, you need to have all the <a href="../../trails/php.html#configuration">
required software installed and configured for PHP development</a>. </p>
<h2><a name="editorLayout"></a>The NetBeans IDE for PHP Editor Layout</h2>
<p>The editor contains the following windows:</p>
<ul>
<li>The Editor window shows the file you are editing. The Editor has
a tab for every open file.</li>
<li>The Projects window shows a list of currently existing projects</li>
<li>The Files window shows the files for each project</li>
<li>The Services window shows lists of currently available external services such as databases.</li>
</ul>
<p>You can also open a Navigator window in the left-hand panel by pressing Ctrl + 7.
The Navigator shows the structure of a PHP class if the class is open in the Editor.
Non-class PHP files are not shown in the Navigator window.</p>
<p>To open help for one of these windows, select any element in the window and press F1.</p>
<h2><a name="SyntaxHighlighting"></a>Syntax Highlighting </h2>
<p>The editor provides syntax highlighting for PHP, HTML, JavaScript, and CSS code blocks. </p>
<p>The following syntax elements are highlighted in the current version:</p>
<ul>
<li>PHP keywords and variables<br><img src="../../../images_www/articles/72/php/editorguide/keywords.png" alt="Highlighted PHP keywords" width="402" height="86" class="margin-around b-all"></li>
<li>PHP constants and &quot;magic constants&quot;<br><img src="../../../images_www/articles/72/php/editorguide/magic-constant.png" alt="magic constant" width="341" height="20" class="margin-around b-all"></li>
<li>HTML tags, including input form attributes<br><img src="../../../images_www/articles/72/php/editorguide/html.png" alt="HTML highlighting in PHP file" width="574" height="85" class="margin-around b-all"></li>
<li>Apache web server <code>.htaccess</code> or <code>httpd.conf</code> files<br><img src="../../../images_www/articles/72/php/editorguide/improvements-in-coloring-1.png" alt="Highlighted httpd.conf file content" width="537" height="182" class="margin-around b-bottom b-right"></li>
<li>PHP numbers</li>
<li>HTML tags inside PHPDoc comment blocks<br><img src="../../../images_www/articles/72/php/editorguide/improvements-in-coloring-2.png" alt="Highlighted PHP Numbers and HTML tags inside PHPDoc block" width="319" height="238" class="margin-around b-right b-bottom"></li>
<li>The current line is displayed with a light-blue background.<br><img src="../../../images_www/articles/72/php/editorguide/highlight-selected-line.png" alt="Current line with blue highlighting" width="409" height="89" class="margin-around b-all"></li>
<li>By placing the caret inside a PHP variable, a function, or a class,
all the occurrences of the variable are highlighted. <img src="../../../images_www/articles/72/php/editorguide/select-variable.png" alt="Variable selected" width="360" height="189" class="margin-around b-all"></li>
<li>Lines where errors have been detected are underlined in red.<br><img src="../../../images_www/articles/72/php/editorguide/error.png" alt="Highlighted error" width="365" height="54" class="margin-around b-all"> </li>
</ul>
<br>
<p>To change the settings for highlighting, choose <tt>Tools > Options</tt> and switch to the Fonts&amp;Colors tab.
Specify the settings of your choice.</p>
<h2><a name="goToDeclaration"></a>Go To Declaration</h2>
The Go To Declaration function navigates the user from an occurrence of a
variable or function to the line where the variable or function is declared or initialized.
To use this functionality, position the cursor on the relevant variable or function occurrence
and choose Navigate &gt; Go to Declaration from the context menu, or press Ctrl-B/&#8984;-B, or use Ctrl-click.
<h2><a name="Navigator"></a>Navigator Window</h2>
<p>The Navigator window displays code structures as elements of a list that shows the
PHP structures of the currently active file. If the file contains
any other text sources (for example, HTML) the list displays their structures too.
By double-clicking a function or a variable in the list,
the cursor points at the declaration of the clicked element. </p>
<p class="alert"><b>Caution:</b> The Navigator window only shows PHP code for PHP
classes. It cannot show PHP code outside of a class.</p>
<p>The Navigator list does not normally contain any embedded lists,
but for complex statements it may contain embedded structures.
For example, a PHP class declaration statement can be presented as
a tree of declared class members. </p>
<p>The list is dynamically updated while the user types the code. </p>
<p>The Navigator window is shown in the bottom of the left-hand panel.</p>
<ol>
<li>To open the Navigator window, press Ctrl + 7 or go to Window &gt; Navigating &gt; Navigator.
The tree that displays the hierarchy of the HTML and PHP structures appears.</li>
<li>To move to the desired element, double click the relevant node in the list.
<br>
<img src="../../../images_www/articles/72/php/editorguide/using-navigator-window.png" alt="Using the Navigator window to select function" width="536" height="145" class="margin-around b-top b-right b-bottom"></li>
</ol>
<h2><a name="CodeFolding"></a>Code Folding</h2>
<p>The editor enables the user to selectively hide and display modules,
classes or functions of the currently edited file with PHP source code. To fold or display a piece of code, click the - or + icon to the left of the code,
or press Ctrl+ or Ctrl-. </p><img src="../../../images_www/articles/72/php/editorguide/improved-code-folding-1.png" alt="Code folding as of NB 7.2" width="536" height="378" class="margin-around">
<h2><a name="SmartIndent"></a>Smart Indent</h2>
<p>The editor automatically formats the code while the user is typing. </p>
<h2><a name="Formatting"></a>Formatting</h2>
<p>To format a piece of code to make it more understandable, perform the following steps:</p>
<ol>
<li>Select the relevant code passage.</li>
<li>From the right-mouse context menu, choose Format or press Alt + Shift + F</li>
</ol>
<h2><a name="BracketCompletion"></a>Bracket Completion</h2>
<p>The editor automatically adds and removes matching brackets and quotes while the user is typing the code. </p>
<ul>
<li>Paired single ' ' and double quotes &quot;&quot; &quot;&quot;, braces (), and brackets [] are added when the user has typed the first symbol.</li>
<li>At the end of a line, a semicolon is added in addition to the closing single or double quote.</li>
<li>The closing curly brace is added after the user presses Enter, which also activates the Smart Indent function.</li>
<li>Deleting the opening single or double quote, brace, or bracket causes automatic removal of the corresponding closing symbol but does not affect the line end semicolon.
<li>When the cursor points at a closing brace ), a closing curly brace }, or a closing bracket ], the paired opening symbol is highlighted in yellow.
<br>
<img src="../../../images_www/articles/72/php/editorguide/bracket-highlighting.png" alt="Bracket highlighting" width="367" height="259" class="margin-around b-all"></li>
</ul>
<h2><a name="instant-rename"></a>Rename Refactoring and Instant Rename</h2>
<p>You can rename an element such as a class name across all files in a project.
The feature forces you to preview your changes before you can make them.
The preview window shows you every location of the element and lets you
exclude individual occurrences of the element from being renamed.</p>
<p>Rename Refactoring is contrasted with the older feature, Instant Rename.
Instant Rename is still available, but it only works in "non-public" contexts,
such as renaming a variable inside a method, or renaming private variables and fields.
Instant Rename lets you only rename an element within a file and does not provide a preview window.</p>
<p>To use Instant Rename, place the cursor on a name you want to change and press Ctrl-R. If Instant Rename applies to that variable, all instances of that variable or function name are highlighted.</p>
<img src="../../../images_www/articles/72/php/editorguide/refactor-ctrlr.png" width="551" height="361" alt="PHP code editor after Ctrl-R pressed">
<p> Change one instance of the name and all other instances in the file are changed simultaneously</p>
<img src="../../../images_www/articles/72/php/editorguide/refactor-afterchange.png" width="551" height="359" alt="PHP code editor showing a refactored variable name">
<p>To use Rename Refactoring, select the element you want to rename and either press Ctrl-R or right-click and select Refactor &gt; Rename.
A dialog opens for you to rename the element.</p>
<img src="../../../images_www/articles/72/php/editorguide/rename-confirm.png" alt="Dialog for renaming a variable" class="margin-around" >
<p>Rename the element and press Preview. The Refactoring window opens. In this window, you can find every instance of
the element in your project and decide whether or not to rename it.</p>
<img src="../../../images_www/articles/72/php/editorguide/refactoring.png" alt="Refactoring window" class="margin-around" >
<p>For more information about Rename Refactoring, see the screencast <a href="../../docs/php/screencast-rename-refactoring.html">Rename Refactoring and Other Editor Improvements
in NetBeans IDE 7.0 for PHP</a>.</p>
<h2><a name="CodeCompletion"></a>Code Completion</h2>
<p>Code Completion is a common name for a set of features that speed up
the process of coding.</p>
<p>The following types of code completion are distinguished: </p>
<ul>
<li><a href="#snippets">Snippets</a></li>
<li><a href="#contextSensitiveProposals">Context-sensitive proposals</a></li>
<li><a href="#abbreviations">Abbreviations</a></li>
<li><a href="#cc-constructors">Code Completion in Constructors</a></li>
<li><a href="#cc-sql">SQL Code Completion</a></li>
<li><a href="#cc-namespaces">PHP 5.3 Namespaces</a></li>
<li><a href="#cc-overridden-methods">Overridden and Implemented Methods</a></li>
</ul>
<div class="indent"><h3><a name="snippets"></a>Snippets </h3>
<p>Snippets enable the user to generate code for various elements automatically.</p>
<ol>
<li>Choose Tools &gt; Palette &gt; Code Clips. A palette containing various user interface elements appears in the right-hand panel.</li>
<li>Drag the required icon on the palette to the relevant position in the code. A dialog box for specifying the parameters of the corresponding elements appears. Fill in the data.</li>
<li>The code that displays the chosen element is generated and inserted in the chosen location.</li>
</ol>
<h3><a name="contextSensitiveProposals"></a>Context-Sensitive Proposals </h3>
<p>The editor provides context-sensitive proposals for completing any number of starting symbols of: </p>
<ul>
<li>A PHP keyword (for example, if, else, elseif, while, switch, function, and so on) </li>
<li>A PHP built-in function ( for example, substr, count, and so on)</li>
<li>A pre-defined or user-defined variable</li>
</ul>
<p>The editor not only suggests expansions but also provides <a href="#ParameterHints">parameter hints</a>. To apply Code Completion: </p>
<ol>
<li>Type the starting symbols of the required character string. </li>
<li>Press Ctrl + Space. A dropdown list shows the context-sensitive proposals. Each proposal is supplied with a description and parameter hints. The contents of the list change as you continue typing. <br><img src="../../../images_www/articles/72/php/editorguide/function-cc.png" alt="Function code completion" width="523" height="503" class="margin-around b-all"></li>
<li>To obtain a list of the PHP key words that are available in the current context, press Ctrl + Space without any previous typing.
</li>
<li>To obtain a hint on a variable, just type the dollar symbol &quot;$&quot;. A list of all the currently available local and global variables appears.
<br>
<img src="../../../images_www/articles/72/php/editorguide/variable-cc.png" alt="Variable code completion" width="437" height="476" class="margin-around b-all"></li>
</ol>
<h3><a name="abbreviations"></a>Code Templates and Abbreviations</h3>
<p>In the current context, the term &quot;&quot;abbreviations&quot; refers to a set of predefined character strings that correspond to the key words used in a programming language. Each abbreviation is associated with an expanded text which contains the full key word and a code template for the key word with parameter hints. To apply this functionality, type an abbreviation and press Tab. </p>
<img src="../../../images_www/articles/72/php/editorguide/template-abbr.png" alt="Template abbreviation" width="98" height="51" class="margin-around b-all"><br>
<p>The abbreviation is replaced with the corresponding key word and the code template for the key word is provided.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/template-expanded.png" alt="Expanded cls template" width="269" height="167" class="margin-around b-all"></p>
<p>In the code template, if the cursor is in a blue box with a violet border, the cursor is in a field in the template. Type the field name or value. All instances of that field also change value. Press Enter when you are finished, and the cursor moves to the next field (or to the position of the <code>${cursor}</code> variable, or outside the template if there are no remaining fields).
</p>
<img src="../../../images_www/articles/72/php/editorguide/template-secondfield.png" alt="Template with second field selected" width="269" height="173" class="margin-around b-all">
<p>To view the list of defined abbreviation with code templates:</p>
<ol>
<li>Choose <tt>Tools > Options > Editor > Code Templates</tt>. </li>
<li>From the Language drop down list, select PHP. The list of PHP abbreviations and code template defined for them is displayed.</li>
<li>To add or remove a definition from the list, use the New or Remove buttons respectively.</li>
<li>To edit a definition, select the relevant row and edit the text in the edit field below the list. <br>
<img src="../../../images_www/articles/72/php/editorguide/code-template-definitions-list.png" alt="The list of sbbreviations and code templates defined for them" width="536" height="513" class="margin-around"></li></ol>
<p>For more information, please see <a href="../../docs/php/code-templates.html">Code Templates in NetBeans IDE for PHP</a>.</p>
<h3><a name="cc-constructors"></a>Code Completion for Constructors</h3>
<p>After the <tt>new</tt> keyword, the code completion window is displayed with constructors and parameters for all available classes in the project.</p>
<img src="../../../images_www/articles/72/php/editorguide/cc-constructor.png" width="600" height="408" alt="Code completion hints for a constructor" class="margin-around" border="1">
<h3><a name="cc-sql"></a>SQL Code Completion</h3>
<p>SQL code completion displays when a string begins with the SQL keyword &quot;select.&quot; The first step is to select the database connection.</p>
<img src="../../../images_www/articles/72/php/editorguide/cc-sql.png" height="384" width="475" alt="Code completion offering database connection" border="1" class="margin-around">
<p>All database connections registered with the IDE are displayed.</p>
<img src="../../../images_www/articles/72/php/editorguide/cc-sql-dbconnections.png" alt="All database connections registered with the IDE" width="554" height="185" class="margin-around">
<p>After you select the connection, SQL code completion offers all tables from that database connection. </p>
<p><img src="../../../images_www/articles/72/php/editorguide/cc-sql-tables.png" height="384" width="494" alt="All tables in the wishlist db connection" class="margin-around" border="1"></p>
<p>If the table has columns, those are displayed as well.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/cc-sql-columns.png" height="358" width="530" class="margin-around" alt="Columns shown for table" border="1"></p>
<p>SQL code completion also works with table aliases.</p>
<img src="../../../images_www/articles/72/php/editorguide/cc-sql-aliases.png" alt="SQL code completion showing tables in hotel alias" height="352" width="537" border="1" class="margin-around">
<h3><a name="cc-namespaces"></a>PHP 5.3 Namespaces</h3>
<p>Code completion supports fully qualified, partially qualified, and unqualified namespace names from PHP 5.3. For more information, please see our <a href="../../docs/php/namespace-code-completion-screencast.html">screencast</a>.</p>
<p>The IDE also helps you resolve missing namespace <tt>use</tt> statements.
<em>Inside a namespace</em> where you want to fix missing <tt>use</tt> statements,
either right-click and select Fix Uses..., or press Ctrl-Shift-I and go to Source &gt;
Fix Uses... A dialog opens offering fully qualified names for each needed use statement.
For more information, see <a href="https://blogs.oracle.com/netbeansphp/entry/how_to_fix_your_use">
How to Fix Your Use Statements</a>.</p>
<h3><a name="cc-overridden-methods"></a>Overridden and Implemented Methods</h3>
<p>Code completion between class members offers to override or implement methods.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/cc_overriden_methods.png" alt="Code completion offering to override method" width="600" height="478" class="margin-around"></p>
<h3><a name="clever-catch-cc"></a>Clever Try/Catch Code Completion</h3>
<p>Starting in NetBeans IDE 7.1, code completion for <tt>catch</tt> statements includes only classes that inherit from <tt>Exception</tt>.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/clever-catch-cc.png" alt="Editor showing clever code completion in catch parameters" width="491" height="166" class="margin-around b-all"></p>
<h3><a name="annotations">Annotations</a></h3>
<p>NetBeans IDE code completion supports the following types of PHP annotations:</p>
<ul>
<li>ApiGen (legacy PHPDoc annotations)</li>
<li>PHPUnit</li>
<li>Doctrine 2 (ORM and ODM)</li>
<li>Symfony 2</li>
</ul>
<p>Every annotation can be associated with a context. NetBeans IDE recognizes four contexts:</p>
<ul><li>function</li>
<li>class/interface (type)</li>
<li>method</li>
<li>field</li></ul>
<p>You can add more annotations to code completion in Tools &gt; Options &gt; PHP &gt; Annotations.</p>
<h3><a name="traits"></a>PHP 5.4 Traits</h3>
<p>Traits are a mechanism of code reuse introduced in PHP 5.4.0. (For information about traits, see <a
href="http://php.net/manual/en/language.oop5.traits.php">
php.net documentation</a>.) NetBeans IDE recognizes traits syntax and code completion includes methods, functions, and anything else inherited from or declared in a trait. </p><img src="../../../images_www/articles/72/php/editorguide/php54-traits-1.png" alt="Trait code completion" width="435" height="472" class="margin-around b-all">
</div>
<h2 id="php54">PHP 5.4 Support</h2>
<p>NetBeans Editor for PHP offers a number of features specific to
developing with PHP 5.4.</p>
<ul>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_array">
Array Dereferencing</a></li>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_anonymous">
Anonymous Object Variable</a></li>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_short">
Short Array Syntax</a></li>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_built">
Built-In Web Server</a></li>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_traits">
Code Completion for Traits</a></li>
<li><a href="https://blogs.oracle.com/netbeansphp/entry/php_5_4_support_minor">
Other features</a></li>
</ul>
<h2><a name="rectangular"></a>Rectangular Selection</h2>
<p>NetBeans IDE 7.1 for PHP introduces the Rectangular Selection action. This editing function is useful in cases such as deleting line numbers in pasted code.</p>
<p>To enable rectangular selection, press the Rectangular Selection toggle button or Ctrl-Shift-R.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/rec-selec-togglebutton.png" alt="Editor showing Rectangular Selection toggle button" width="600" height="321" class="margin-around b-all"></p>
<p>When Rectangular Selection is enabled, you can make the selection with mouse or keyboard. When you use the keyboard, place the caret on a corner, keep SHIFT pressed down, and select what you need with the arrows keys. </p>
<p><img src="../../../images_www/articles/72/php/editorguide/rec-selec-made.png" alt="Editor showing a rectangular selection of pasted line numbers" width="600" height="289" class="margin-around b-all"></p>
<p>f you write text while an area is selected, the text is placed on every line in the selected area. This can be useful, for example, for simultaneously changing the access modifiers of multiple fields in a class. </p>
<p><img src="../../../images_www/articles/72/php/editorguide/rec-selec-addtext.png" alt="Editor with an access modifier added to all lines in a rectangular selection" width="435" height="342" class="margin-around b-top b-right"></p>
<h2><a name="phpdoc"></a>ApiGen Support</h2>
<p>Built-in support for ApiGen was added in NetBeans IDE 7.2. For more information, see the
screencast <a href="../../docs/php/screencast-apigen.html">Generating PHP Documentation With NetBeans IDE</a>.</p>
<p class="alert"><b>Warning:</b> PHPDocumentor does not fully support PHP 5.3. Namespaces and some other 5.3 features are not documented by PHP Documentor.</p>
<h2><a name="code-generators"></a>Code Generators</h2>
<p>When you press the combination Alt-Insert (Ctrl-I on Mac), a menu opens with all possible code generators. The list of generators is context sensitive. It depends on the position of the caret in the code when the key combination is pressed. Depending on your position in the code, you can generate a database connection, database tables, lorum ipsum text, and several others. This section describes only the following code generators:</p>
<ul>
<li><a href="#generate-constructors">Constructors</a></li>
<li><a href="#generate-getters-setters">Getters and Setters</a></li>
<li><a href="#generate-overriden-methods">Overridden and Implemented Methods</a></li>
</ul>
<div class="indent">
<h3><a name="generate-constructors"></a>Constructors</h3>
<p>You can generate constructors by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class body, but not inside any functions contained in that body. When you select Generate... Constructor, a dialog opens llisting the fields you can initialize by the constructor. The field names are used as parameters of the constructor.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/generate-constructor-fields.png" alt="Dialog of fields to initialize with constructor" width="352" height="299" class="margin-around"></p>
<p>You can decide not to select any fields. In this case, the IDE generates an empty constructor, with no parameters. If the field is a class with properties, you can either select individual properties, or you can select the class, in which case all the class' properties are selected automatically.</p>
<p>For more information, see the <a target="_blank" href="http://blogs.oracle.com/netbeansphp/entry/generate_constructor_getters_and_setters">NetBeans PHP blog post</a>.</p>
<h3><a name="generate-getters-setters"></a>Getters and Setters</h3>
<p>You can generate getters and setters by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class body and selecting Getter, Setter, or Getters and Setters. Only the possible functions are displayed. For example, if you already have setters for the available properties, only the getter option appears.</p>
<p>When you select Generate... Getter/Setter/Getter and Setter, a dialog appears with the properties for which you can generate a getter or setter. The properties are displayed in a tree. If you select a parent class, you automatically select all that class' properties.</p>
<p>You can name a getter or setter according to either the convention getName or the convention get_name.</p>
<p>For more information, see the original <a target="_blank" href="http://blogs.oracle.com/netbeansphp/entry/generate_constructor_getters_and_setters">NetBeans PHP blog post</a> and the post on <a target="_blank" href="http://blogs.oracle.com/netbeansphp/entry/generating_getters_and_setters_improved">improved getter and setter generation</a>.</p>
<h3><a name="generate-overriden-methods"></a>Overridden and Implemented Methods</h3>
<p>You can generate overridden or implemented methods by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class declaration and there are multiple class members. A dialog opens showing the methods you can insert and indicating whether they are overridden or implemented.</p>
<p><img class="margin-around" src="../../../images_www/articles/72/php/editorguide/generate_overriden_methods.png" alt="Dialog for generating overridden methods" width="523" height="520"></p>
<p>This feature complements the &quot;Implement all abstract methods&quot; hint and <a href="#cc-overridden-methods">code completion for overridden and implemented methods</a>.</p>
<p>For more information, see the <a target="_blank" href="http://blogs.oracle.com/netbeansphp/entry/generate_overriden_implemented_methods">NetBeans PHP blog post</a>.</p>
</div>
<h2><a name="ParameterHints"></a>Parameter Hints </h2>
<p>The editor prompts the user regarding the formal parameters of a function or a method in the context where the function or method is called.</p>
<ol>
<li>Type the starting characters of the function you want to call. </li>
<li>Press Ctrl + Space. A dropdown list shows the context-sensitive proposals with the formal parameters for each proposal.<br>
<img src="../../../images_www/articles/72/php/editorguide/parametr-hint-one.png" alt="List of context-sensitive hints" class="margin-around">
</li>
<li>Choose the relevant proposal and press Enter. The name of the chosen function is inserted in the code and a template for entering the parameters is shown in brackets. <br>
<img src="../../../images_www/articles/72/php/editorguide/parametr-hint-two.png" alt="Parameter hints for the chosen context-sensitive proposal." class="margin-around">
</li>
</ol>
<h2><a name="vartyp-cmnt"></a>Defining Variable Type in Comments</h2>
<p>You can define a variable and its type in a comment. The comment has to be in the format <em>/* @<strong>var</strong> $variable type */ </em>. If the comment is written correctly, the <em><strong>var</strong></em> tag is in bold font.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/vardoc-basic.png" height="319" width="600" alt="Variables declared in comments" class="margin-around" border="1"> </p>
<p>You can use the code template <tt>vdoc</tt>, followed by Tab, to generate a comment that defines a variable. The variable name is selected, and you can change it. Then press Tab again, and the type is selected.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/vardoc-template.png" height="269" width="600" alt="Variable declaring comment generated by vdoc template" class="margin-around" border="1"> </p>
<p>The code template automatically sets the variable name and type. If a variable is used after the place where you insert the template, then that following variable name is suggested by default. If there is not any variable used after the place where you insert the template, but there is a variable used above the template, then that preceeding variable name is suggested as default. If NetBeans IDE is not able locate any variable near where you use the template, then the default name is <em>variable</em>.&nbsp; The variable type is set automatically according to the same rules.</p>
<img src="../../../images_www/articles/72/php/editorguide/vardoc-template-names.png" alt="Variable declaring comment generated by vdoc template, with default variable names and types" class="margin-around" border="1" height="385" width="600">
<h2><a name="errorMessages"></a>Error Messages</h2>
<p>The editor analyzes the syntax of the code while you type, and marks syntax errors by underlining the erroneous lines and setting a red bullet next to them. To get an explanation of the error, mouse over the erroneous line or click the red bullet. A tooltip appears with a short explanation of the error. <br>
<img src="../../../images_www/articles/72/php/editorguide/error-messaging-m1.png" alt="Error-messaging: a tooltip above the erroneous line." class="margin-around">
</p>
<h2><a name="phpunit"></a>PHPUnit and Selenium Tests</h2>
<p>NetBeans IDE for PHP supports <a target="_blank" href="http://www.phpunit.de">PHPUnit</a> automated tests, including code coverage. You can use test groups in your code.</p>
<p>NetBeans IDE also supports the Selenium portable test framework, in combination with PHPUnit. A Selenium plug-in is available from the Update Center. Installing this plugin adds a Selenium server to the IDE's registered servers and adds Selenium test options to the PHP menus.</p>
<p>See <a href="../../docs/php/phpunit.html">Testing with PHPUnit and Selenium</a> for more information.</p>
<h2 id="spellchecker">Spellchecker</h2>
<p>A spellchecker is available. In the Options dialog, you can switch spellchecking on or off for different languages.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/spellchecker-options.png" class="margin-around" alt="Options dialog for spellchecker" width="600" height="448"></p>
<p>In the Options dialog, you can add and remove new dictionaries and set the locale.&nbsp; When you want to add a new dictionary, you have to have a file with the words. The format of the dictionary file is a list of words with every word on a new line. You have to tell NetBeans the encoding of the dictionary file and for which locale the file should be used. </p>
<p><img src="../../../images_www/articles/72/php/editorguide/spellchecker-newdictionary.png" class="margin-around" alt="Adding a new dictionary to the spellchecker" width="600" height="180"></p>
<p>When the spellchecker finds a word that is not in its dictionary, it underlines that word in red. The spellchecker also adds a tooltip to that word that says &quot;Misspelled word.&quot; Note that HTML text is checked in PHP files.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/spellchecker-html.png" alt="Errors found in HTML text in PHP file" width="600" height="68" class="margin-around"></p>
<h2><a name="symfony"></a>Symfony, Symfony2, and Zend Framework Support</h2>
<p>Symfony, Symfony2, and Zend framework support are built-in to the PHP editor. It recognizes existing Symfony and Zend frameworks, and you can add the framework to new projects in the last panel of the new PHP project wizard.</p>
<p>In a PHP project with Symfony, Symfony2, or Zend support, you can run Symfony or Zend commands from the project's context menu.</p>
<img src="../../../images_www/articles/72/php/editorguide/symfony-contextmenu-commands.png" alt="Context menu showing Symfony commands" class="margin-around">
<p>Use the UI for the commands to:</p>
<ul>
<li>Filter the Symfony/Zend commands (1)</li>
<li>Specify command parameters (2)</li>
<li>Select a command (3)</li>
<li> See the command's context help (4) </li>
<li>Preview the entire command that will be run (5)</li>
</ul>
<img src="../../../images_www/articles/72/php/editorguide/symfony-command-dialog.png" class="margin-around" alt="Annotated Symfony command dialog">
<p>The list of commands is project specific. This means that if one uses e.g. Doctrine instead of Propel, no Propel commands are listed, just the Doctrine ones. Also, all the commands from the project's Symfony plugins are available.</p>
<p>Code completion includes Symfony variables in Symfony views, Symfony2 variables in Symfony2 views, and Zend variables in Zend views. </p>
<img src="../../../images_www/articles/72/php/editorguide/symfony-variables.png" alt="Symfony variables in code completion" class="margin-around" border="1">
<p>The IDE also provides navigation shortcuts between Symfony or Zend views and actions. These shortcuts were improved in NetBeans 6.9. In addition, code completion in <em>view</em> templates/files now includes variables that are declared in <em>controller/action</em> files. See the <a target="_blank" href="http://blogs.oracle.com/netbeansphp/entry/framework_support_improvements">NetBeans PHP blog post</a> for details.</p>
<p>For more about our Zend framework support, please see the Zend <a href="../../docs/php/zend-framework-screencast.html">screencast</a>.</p>
<h2><a name="smarty"></a> Smarty Support</h2>
<p>NetBeans IDE includes a plugin for Smarty framework support. This support includes basic Smarty 3 features, namely Smarty 3 code completion and delimiters.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/smarty3.png" alt="Editor showing basic Smarty 3 support" width="364" height="136" class="margin-around b-all"></p>
<p>Toggle between Smarty 3 and Smarty 2 behavior in the Options window. Go to Tools &gt; Options (NetBeans Preferences on MacOS), select PHP, and open the Smarty tab. The Smarty framework plugin must be installed.</p>
<p><img src="../../../images_www/articles/72/php/editorguide/smarty-options.png" alt="Smarty options" width="586" height="480" class="margin-around"></p>
<h2 id="doctrine2">Doctrine2 Support</h2>
<p>If you have Doctrine2 ORM and its requisite packages installed, you can use NetBeans IDE's code
completion with Doctrine2 functions and you can run Doctrine2 commands from the IDE. You need
to set the path to the Doctrine2 run script in the IDE's Options, and your PHP project has to have Doctrine2 enabled. See
<a href="https://blogs.oracle.com/netbeansphp/entry/doctrine2_support_added">Doctrine2 Support Added</a>
in the NetBeans PHP blog for details.</p>
<h2><a href="/about/contact_form.html?to=3&amp;subject=Feedback:%20PHP%20Editor%20Guide">Send Feedback on This Tutorial</a></h2>
<br style="clear:both;" >
<p>To send comments and suggestions, get support, and keep informed on the latest
developments on the NetBeans IDE PHP development features, <a href="../../../community/lists/top.html">join
the users@php.netbeans.org mailing list</a>.</p>
<p><a href="../../trails/php.html">Back to the PHP Learning Trail</a></p>
</body>
</html>