views:

44

answers:

1

Hi all,

I am doing some self-learning about cakePHP 1.26.
I got a table which has two fields {topic, username}

I got a simple HMTL form like this:

<input type=text name="data[testing][topic]" id="data[testing][topic]"/>

The data from this input field was passed to the specific controller with this code:

$who=$this->Session->read('user.name'); // username retrieved successfully
$this->Testing->save($this->data);

When I checked the database, I could only see the data from the Input text field, but the username field is empty. How do I alter the code in the controller so that the username retrieved from the session can be saved into the database?

Could you help me please?

+2  A: 

Like this:

$who=$this->Session->read('User.id');
$this->data['Testing']['user_id'] = $who; // set the data
$this->Testing->save($this->data);
Sergei