user327712
user327712

Reputation: 3321

The save() method in cakePHP

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?

Upvotes: 3

Views: 3651

Answers (2)

Sajan Patel
Sajan Patel

Reputation: 51

$hello=$this->Session->read('Test.name');

$this->data['Testing']['test_name'] = $hello;

$this->Testing->save($this->data);

Upvotes: 1

Sergei
Sergei

Reputation: 2757

Like this:

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

Upvotes: 2

Related Questions