Using Netbeans to generate PHP class methods

One of the features that I was previously unaware of in Netbeans is its ability to automatically generate common class methods. This post is a quick guide of how this works for future reference.

To get the system to work, first load up a php class. For this example I’m going to be extending the Magento Product Model. This basic class can be seen here, with a couple of extra properties added. Image

To start generating the methods you need to press [Alt] & [Insert] and you will be presented with a menu similar to the one below

Image

This lists all of the common methods that do not currently exist within the class. The first thing that we’ll do is to generate a constructor, which gives us the following options

Image

Here you can select which of the class properties you want to be set using the constructor. Pick the ones you want and click OK, and the following code is generated

Image

The Getters and Setters work in the same way, and the Override & Implement provides you with a list of all of the methods that the class can override from its parents. Using these together can help you to quickly all of the methods you need in minutes, as shown below.

Image


Tags: developmentphpmagentoclassmethodshelpful tips