Jump to content

Not able to understand cakephp code format


piyusharora420

Recommended Posts

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

 

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();

 

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.