Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Cake 2.0 vs Cake 3.0 - Declare Model & Controller Class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 105
    Comment on it

    CakePHP 2.x supports PHP Version 5.2.8 and above while CakePHP 3.x supports PHP Version 5.4.16 & above. There are some changes from CakePHP 2.x to 3.0 like syntax declaration , array declaration & model defination etc.
    The config key www_root has been changed to wwwRoot. Here is model & controller declaration examples which will give you a basic idea about CakePHP3.0

    Example of usercontroller in 3.0

    namespace App\Controller;
    namespace App\Controller;
     class UsersController extends AppController {
     
        public $components = [
            'Paginator'
        ];
     
        public function index() {
            $this->set('users', $this->Paginator->paginate($this->Users, [
                'limit' => 5,
                'conditions' => [
                    'Users.active' => 1
                ]
            ]));
        }
    }

    Example of usercontroller in 2.0
     

    <?php
       
    App::uses('AppController', 'Controller');
    
    class AdminsController extends AppController {
    
        public $components = array('paginater');
    
            public function index() {
            $this->set('users', $this->Paginator->paginate($this->Users, array(
                'limit' => 5,
                'conditions' => array(
                    'Users.active' => 1
                )
            )));
        }
    
    }

    Ex: Model In 3.0

    namespace App\Model\Repository;
     use Cake\ORM\Table;
    
    class UsersTable extends Table {
     
    }

    //The UsersTable, formerly known as a Model in 2.0.

    Ex: Model in 2.0

    <?php
    App::uses('AppModel', 'Model');
    
    class User extends AppModel {
    
    }

     

 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: