make a controller name Pagescontroller.php and paste the following below code
<?php
class PagesController extends AppController {
public $name = 'Pages';
/* Use Customer model */
public $uses = array('Customer');
public function display() {
/* form submitted? */
if (!empty($this->request->data)) {
/* save record */
$this->Customer->save($this->request->data);
}
/* find all customers in database */
$customers = $this->Customer->find('all');
/* pass customers to view */
$this->set('customers', $customers);
/* display home.ctp instead of default display.ctp */
$this->render('home');
}
}
In above code:
if (!empty($this->request->data)) { - It send the request to submit the form.
$this->Customer->save($this->request->data);--> Saves the data of input form into database
$customers = $this->Customer->find('all'); -> search the database to find all the records
$this->render('home');- > this will view the home ctp file to show all the records that are fetch from database
make a new file name Home.ctp in view folder and paste the below code
<?php
echo $this->Time->format('F jS, Y h:i A', time());
?>
0 Comment(s)