1

I see that there are no getter and setter methods in cakePHP Models to access columns in a database (like there is in symfony). Without those getter and setter methods, I can't really do pure OOP programming in cakePHP.

I can't for example create an object called let's say Book like:

$book = new Book();

And now access books' properties like so:

$title = $book->getTitle();
$author = $book->getAuthor();

etc... Does anybody know how I can get such pure OOP functionality in cakePHP? Or do I have to implement those getters and setters myself in the Model.

Thanks in advance

hakre
  • 193,403
  • 52
  • 435
  • 836
user765368
  • 19,590
  • 27
  • 96
  • 167
  • 5
    "Without those getter and setter methods, I can't really do pure OOP programming in cakePHP." This does not make any sense to me... OOP _requires_ (ugly) Getter/Setters? – KingCrunch Feb 04 '12 at 00:35
  • Indeed, pure OOP does not need getters and setters. See [Java: Are Getters and Setters evil?](http://stackoverflow.com/questions/565095/java-are-getters-and-setters-evil) and the [original article](http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html) (ignore the always-pointless "is evil" overdramatizing, still some relevant advise in the end) and a [PHP assessment](http://berryllium.nl/2011/02/getters-and-setters-evil-or-necessary-evil/) – mario Feb 04 '12 at 00:48
  • Cake's models are hardly OOP to begin with. You can always implement your own objects on top of Cake's models with all the OOPness you want. – deceze Feb 04 '12 at 02:30
  • I'm confused. Why is it that you need setters and getters inside CakePHP? What is it that you are trying to do that requires getters and setters? – Chuck Burgess Feb 16 '12 at 04:02

1 Answers1

2

While it does not use set or get, is this what you are looking for? http://book.cakephp.org/1.3/en/view/1028/field

There is also this option: http://book.cakephp.org/1.3/en/view/1026/findBy

Maybe I don't fully understand what it is you are trying to accomplish and why the method requires the naming convention to include set and get in order to be considered "pure oop" as you put it. I have not read anywhere that setters and getters are a requirement of the OOP paradigm to be considered "pure oop".

However, if you are stuck trying to do something, I would be happy to help.

Chuck Burgess
  • 11,600
  • 5
  • 41
  • 74