Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.