Good morning my dear freinds.I am here to say you CURD in cake php.
Here I will show you how to view the data in a database using CakePhp.
Lets start..
I need three.That is model ,view and controller.Let us start..
Before that create a database called learncakedb and a tbale called students in it.
Now configure the databse.php file[if you do not know see lesson two in this site]
And your database and table should be like this.
Now create the table with two coloumns ID(varchar 20 primary key) Name(varchar 20) and insert few data into the table.
Here I will show you how to view the data in a database using CakePhp.
Lets start..
I need three.That is model ,view and controller.Let us start..
Before that create a database called learncakedb and a tbale called students in it.
Now configure the databse.php file[if you do not know see lesson two in this site]
And your database and table should be like this.
Now create the table with two coloumns ID(varchar 20 primary key) Name(varchar 20) and insert few data into the table.
Now I create my controller in C:\xampp\htdocs\learncake\app\Controller and save it as StudentsController.php here is the codes
<?php
class StudentsController extends AppController{
public function get(){
$this->loadModel('Student');
$all=$this->Student->get();
$this->set('data',$all);
}
}
?>
Now I need a model.Save the below codes in C:\xampp\htdocs\learncake\app\Model as Student.php
<?php
class student extends AppModel{
public function get(){
$dat=$this->find('all');
return $dat;
}
}
?>
Ok now I need a model to show the data.So first create a floder called Students in C:\xampp\htdocs\learncake\app\View floder and save the view file in it as get.ctp. here is the codes you need.
<?php
foreach ($data as $info) {
echo "<td>{$info['Student']['ID']}</td>";
echo "<td>{$info['Student']['Name']}</td>";
}
?>
That is all.Now go to your web browser and type the below codes in address bar.You will see the below output.
http://localhost/learncake/students/get
Be happy
-Ujitha Manuja Sudasingha-