CakePHP 1.3 introduced a new way to use helpers. This was added to prevent confusion between helper variables and local variables added to the view file. You can access helper methods in a view by using $this->Helper->method(). This way make a problem if you want to use auto-complete for helpers introduced in a previous article
With a small trick you can make netbeans supports this method auto-complete. To do this add a file in your project folder, or preferable to be in CakePHP core folder, with a name dummy_view.php for example. Now add the following code to this file.

Now you’ll see that netbeans displays auto-complete for those helper methods and view methods too like $this->element() for example.

Autocomplete for CakePHP 1.3 helpers in netbeans

How does this work?

The idea here is simple we tell netbeans that there is a new class that extends View class. Then when in view file we tell netbeans to consider that $this has the type DummyView. CakePHP run the code in view files inside render() method in View class so $this is really an instance of View class. Now as netbeans knows the type of $this variable and knows the types of its variables, which are CakePHP helpers, it shows their autocomplete options.

Finally, you should be aware of the following:

Make sure to include your CakePHP core path in netbeans include path or it is inside your project source folder.

This will not load helpers in run time, so make sure you include required helpers in your controller.

You can add your own custom helper in DummyView class using the same method as core helpers.

Debugging code can be the most vital task a developer required to do. Debugging makes it easy to find logical errors in code. NetBeans supports PHP debug using xdebug, but in CakePHP it is hard to make this work straight. This is due to custom, pretty, URL rewriting. However you can enable debugging even with pretty URLs and URL rewriting.
To make this works in simple few steps first make sure that xdebug is installed and working. To make sure it is installed open you php info file or create a new php file and fill it with:

<?php echo phpinfo(); ?>

and open it in your browser and make sure that xdebug appears like this:

XDebug Section in phpinfo()

If you found xdebug is not installed then you can find many resources on how to install xdebug on Google. If it is already installed then make sure that your xdebug is configured correctly in your php.ini. NetBeans requires xdebug to be configured as follows:

Go to Projects panel and right click your project and select Properties from the menu on left select Sources then select your Web Root folder, and it is ovious what to select

Run Configuration and click Advanced. From the dialog select “Ask Every time” and click OK to close the dialog and click OK again to close Project properties dialog.

Now the configurations are complete and you can set break points. To create a break point you can click on the line number on the left of source code or write xdebug_break(); where you want to stop program execution.

Break point in NetBeans

When you click debug icon in NetBeans toolbar, or select Debug project from Debug menu (ctrl + F5), NetBeans will show you a box where you enter the URL you want to debug and it will stop execution of the application, and your browser will not continue loading your page until you click Continue.

NetBeans PHP debug pane

Now you can debug all your CakePHP source code as normal PHP applications. You can learn how to debug normal PHP application in NetBeans from this article

NetBeans is a very powerful development environment for many languages including PHP. With the release of its latest version, NetBeans announced full support for symfony PHP framework. NetBeans can also support many other PHP frameworks and libraries although it is not officially supported by NetBeans. This support needs some effort to enable some tools specially auto-complete, or intellisense, which saves a lot of time for developers.

We will start to make NetBeans support CakePHP. Firstly we need to create a cake project using cake command line tools.

cd DOCUMENT_ROOT
cake bake PROJECT_NAME

Then we need to create a NetBeans project using the create files. Click file > New Project, then choose New Project. From the window choose PHP from categories and from projects choose PHP Application with Existing Sources. Click Next then choose the project path. and click finish.

NetBeans New Project Dialog

After the project is created select the project in the Projects pane and right click Include Path. Click add folder and choose cake library path and add it. NetBeans will scan and add the library to its internal library.

NetBeans PHP include path dialog

Now you will have auto-complete working in your controllers, models, controllers, behaviors and helpers files. This will happen because NetBeans is smart enough to know that your inheriting AppController, AppModel,…etc which in turn inherits Controller and Model classes which is found in CakePHP library directory which NetBeans just scanned. But till now we don’t have support for models and components included magically by CakePHP in controllers and models. To make NetBeans identifies those variables we will use PHPDoc trick. In your model or controller add a variable with the same name of your model or any other model you want, but make sure it is loaded as this will not include your model.

You will notice that NetBeans enables auto-complete even in comments. Just hit Ctrl + Space when writing the name of any class. This will work with associated models in a model class.

Now you will notice that your CakePHP work is much more easier, but we still have auto-complete is not working in views. This problem can be solved using NetBeans feature which enables us to define a variable’s type using comments. I call this feature var-doc or variable type notice. Just write a comment like this before any variable. You even can make this with $this variable to define the class you are working with as View class.

This way you can have auto-complete support for your views and helpers included in views and you will notice that NetBeans also has support for your classes in comments.

At last the only thing that I couldn’t have support for is behaviors methods which can be called from a model’s instances if you now a way to do this please tell me. But we are waiting for more from NetBeans which has introduced too much for us, PHP Developers.

NetBeans has introduced a very powerful development environment for PHP since version 6.5. It has some features that make development even easier. Until NetBeans has launched its 6.8 version, it introduced many features for PHP developers. Here is some features:

Code templates

Code templates is a very powerful feature that can save a lot of time. This templates enables the developer to write few characters which can be expanded to language expressions. Netbeans comes with an excellent group of expressions, but you can add your own templates. Go to tools > options then in the editor section choose Code templates.

Code templates editor in NetBeans PHP editor

Some useful templates can be:

cls: initialize a class with a contructor.

fnc: expands to a function.

fore: foreach statement (foreach($array as $variable))

forek: foreach statement with a key (foreach($array as $key => $var))

to expand an abbreviation press tab, you can set expand trigger also in the code templates editor.

PHP is usually combined with HTML, although it should only be simple statements in view files if you are using MVC pattern. Zen coding project offers a set of code templates for rapid HTML coding.Unfortunately NetBeans didn’t get the full power of Zen coding yet, it only provides code templates :(.

Download Zen coding for NetBeans you will get a ZIP file. Use the code template editor and click ‘Import’ and select this file, then restart NetBeans. Now you get a powerful HTML snippets for NetBeans. You can get a list of all snippets here.

Useful code templates trick, ‘surround with’

Some code templates in NetBeans, and in the template provided with Zen Coding, can be used to surround some text with a code template. This can be useful if you forget, or needed later, to surround some code with certain code template. An example for this is if conditions, loops, ….etc. Those code templates can be used if you select the required code. You will find a small yellow light bulb on the left side of the code, click this bulb to show a list of those templates.

NetBeans code templates surround with dialog

Introduce a variable

NetBeans is very smart when it scans for variable types. It utilizes comments, specially PHPDoc. Variable types is very useful when the IDE displays code completion. But sometimes when you are working on many files many IDEs and code editors doesn’t identify this variable types so the user will miss the code completion feature of the IDE, which saves a lot of time while coding. To retrieve code completion feature again. You can tell NetBeans about the variable type yourself using the following method.

/* @var $variable VariableType */

This will tell NetBeans about the variable you are using and if it is an instance of some class NetBeans will show code completion when required. This can be great if you are using a PHP framework that uses MVC pattern. Personally I use this technique to acquire code completion for CakePHP helpers,