Reputation: 3321
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
Reputation: 51
$hello=$this->Session->read('Test.name');
$this->data['Testing']['test_name'] = $hello;
$this->Testing->save($this->data);
Upvotes: 1
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