3

I have a few PHP classes (X_Model_TableName format), that represent tables in my MySQL database, with just protected properties, and getters/setters, and I've also added a database connection to NetBeans so it can see what's in my database.

Currently I need to add a column to the database, then open the relevant Model_* file, and add a property, and then generate the getter and setters. I'm wondering if there's a way to sort of link a file to a table, so when I add a column to a table, it will either auto-add the necessary code to the PHP class file.

Does NetBeans have any functionality like this available? I've come across this plugin, but it doesn't seem to work, and it's also not exactly what I'm after.

TMH
  • 6,096
  • 7
  • 51
  • 88
  • 1
    you need an ORM like [doctrine](http://www.doctrine-project.org/). Although it wouldnt update the getters/setters it would better represent your model as objects which Im kinda getting from your question is what you might want. – DevDonkey Aug 20 '15 at 14:29
  • 1
    Ahh I didn't think about Doctrine. I think you're right it's what I'm after, but that won't fit in our current MVC without a big rewrite which we unfortunately don't have time for at the moment, definitely something I'll remember for when we do update. – TMH Aug 20 '15 at 14:31
  • @nomistic Netbeans is a good IDE which happens to be able to offer a PHP dev environment. – Alfabravo Aug 20 '15 at 14:34
  • Yup, look at doctrine or other ORMs and build /migration tools like laravel's artisan. – m02ph3u5 Aug 20 '15 at 15:08

1 Answers1

1

I'm not sure about auto-detecting a new column from the db (you might be able to do that with a macro) but once the protected property is defined, you can autogenerate setters and getters like this:

  • Create the new protected property
  • Locate your cursor at the point you want the code inserted
  • Hit Alt-Insert (or right click and select "Insert Code...")
  • Select "Getter and Setter..."
  • Click the properties you want to generate getters and setters for
  • Click OK
  • Profit
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98