Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • find and save the records by using cakePHP models

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 143
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: