My dear friends today I am going to show you how to insert data in to a database using Cakephp.
I will give relavent MVC codes for that.
Now we have created the databse and the table in previous lesson.Now we need only the MVC.
Here is my controller and save it as StudentsController.php in C:\xampp\htdocs\learncake\app\Controller directory.
In the previous lesson we have already created this StudentsController.php so add below coes and save it.
public function insert(){
if($this->request->is('post')){
//$this->Student->save($this->request->data);
$info=$this->request->data;
$this->loadModel('Student');
$all=$this->Student->add($info);
}
Now we have a model called Student[See previous lesson] So open it and add below coeds to it.
public function add($info){
$this->save($info);
}
Now we need a view.So a open a new document and save it as insert.ctp in the C:\xampp\htdocs\learncake\app\View\Students directory.
And this is all.
Go to the browser and type the below codes in address bar and you will see that the data has added to the database.
_Ujitha Manuja Sudasingha-
I will give relavent MVC codes for that.
Now we have created the databse and the table in previous lesson.Now we need only the MVC.
Here is my controller and save it as StudentsController.php in C:\xampp\htdocs\learncake\app\Controller directory.
In the previous lesson we have already created this StudentsController.php so add below coes and save it.
public function insert(){
if($this->request->is('post')){
//$this->Student->save($this->request->data);
$info=$this->request->data;
$this->loadModel('Student');
$all=$this->Student->add($info);
}
Now we have a model called Student[See previous lesson] So open it and add below coeds to it.
public function add($info){
$this->save($info);
}
Now we need a view.So a open a new document and save it as insert.ctp in the C:\xampp\htdocs\learncake\app\View\Students directory.
And this is all.
Go to the browser and type the below codes in address bar and you will see that the data has added to the database.
_Ujitha Manuja Sudasingha-