piyusharora420 Posted July 17, 2012 Share Posted July 17, 2012 Hello Everyone, I have just started working on cakephp framework. I have seen methods like $this->Form->input. I have not worked ever with such things. I can understand $this->variableName or $this->methodName. But what is meaning of "Form" there? Is this calling object of a class in other class? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/ Share on other sites More sharing options...
gizmola Posted July 17, 2012 Share Posted July 17, 2012 That is referring to a class variable $Form, which also happens to be an object. Consider this example: class Request { private $Form; public function setForm($form) { $this->Form = $form; } public function getFormInput() { return $this->Form->input; } } #assume we require() the definition of the Form class... $form = new Form(); $request = new Request(); $request->setForm($form); $input = $request->getFormInput(); Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362085 Share on other sites More sharing options...
piyusharora420 Posted July 17, 2012 Author Share Posted July 17, 2012 Hi, Thanks for the prompt reply. I am afraid, I am still unable to understand it completely. I could not understand "input" in $this->Form->input Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362090 Share on other sites More sharing options...
trq Posted July 17, 2012 Share Posted July 17, 2012 It's just an object within an object, nothing fancy and far from being something that is specific to Cake. Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362111 Share on other sites More sharing options...
piyusharora420 Posted July 17, 2012 Author Share Posted July 17, 2012 Hi Thorpe, Thanks for the response. I think, I have got it. Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362116 Share on other sites More sharing options...
piyusharora420 Posted July 17, 2012 Author Share Posted July 17, 2012 But, I could not understand the benefits of using objects inside objects. Could you please provide me a link where I can see any example? I have gone through the below link: http://www.tuxradar.com/practicalphp/6/6/0 But, it does not explain any benefit. Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362117 Share on other sites More sharing options...
trq Posted July 17, 2012 Share Posted July 17, 2012 It's nothing particular special. It's more a design thing. As an example: Imagine you have a class that represents a database table by exposing the columns as properties. Now, imagine one of the fields in your database is a DATETIME field. It makes sense, to have this field represented as some form of *Date object that would allow you to format this DATETIME field easily. Link to comment https://forums.phpfreaks.com/topic/265805-not-able-to-understand-cakephp-code-format/#findComment-1362123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.