Reputation: 424
I was new to Cakephp and I actually following the tutorial of the Blog tutorial however I didn't follow their database and try my own. Currently my database:
My Model:
class FypCakephp extends AppModel {
//Table Name
public $useTable = 'Report';
public $primaryKey = 'report_id';}
My Controller:
public function add() {
if ($this->request->is('POST')) { //Submited the form:takes a single argument, which can be the request METHOD (get, put, post, delete) or some request identifier (ajax).
$this->FypCakephp->create();// Create a model
// can use the pr() or debug() functions to print it out if you want to see what it looks like.
echo pr(($this->request->data));
debug($_POST);
if ($this->FypCakephp->save($this->request->data)) { //Save to Database and return true.
$this->Session->setFlash(__('Your post has been saved.'));
// return $this->redirect(array('action' => 'index')); //Redirect to the first page
}
$this->Session->setFlash(__('Unable to add your Database.')); //Else will show unable to add
}
}
My View:
Everytime I debug they will show me this http://gyazo.com/7f8f43cbd88aee555aeb6690f33093e0
and they forever took 0 query. When I change the datetime to text type. They also only able to insert the created and modified . May i know what is the reason that cause it ?
Upvotes: 0
Views: 1130
Reputation: 954
Your problem is in view :) Change report to Report. Now when you are saving $this->request->data its trying to find Report key to be able to save , or report field in your database. If you dont want change this , in controller you can save $this->request->data['report']
Edit Also if the first option will not work try FypCakephp instead of report in view. Its must be alias of your model , in your case it is FypCakephp. Also its not a good idea to keep model and table with various names and try too keep name conventions for cakephp (table name report instead Report), but it maybe good for understanding all options :)
Upvotes: 0
Reputation: 2594
@Beginnerk. I saw the above code. Form cakephp point of view, I think its not well structural. In the beginner stage please read the CakePHP 2.x documentation first. Then try to developed a basic crud application. I give the a post link for you.
Creating a CakePHP CRUD Example – Source Code Download and Tutorial
Update - 1
As per as your code save datetime
into database
public function add() {
if ($this->request->is('POST')) {
//Submited the form:takes a single argument, which can be the request METHOD (get, put, post, delete) or some request identifier (ajax).
$this->FypCakephp->create();// Create a model
$data = $this->request->data;
$updated_date = date('Y-m-d H:m:i', strtotime($data['FypCakephp']['updated_date']));
$data['FypCakephp']['updated_date'] = $updated_date;
// can use the pr() or debug() functions to print it out if you want to see what it looks like.
echo pr($data);
debug($_POST);
if ($this->FypCakephp->save($data)) { //Save to Database and return true.
$this->Session->setFlash(__('Your post has been saved.'));
// return $this->redirect(array('action' => 'index')); //Redirect to the first page
}
$this->Session->setFlash(__('Unable to add your Database.')); //Else will show unable to add
}
}
Upvotes: 1