Last Updated: February 25, 2016
·
2.888K
· polidog

call the model method in cakephp

call the general method of model cakephp is

<?php
  class HogeContorller extends AppController {
      public $uses = array('Test');

      public function index() {
          $this->Test->hoge();
      }
  }

that code is not nice... use $use Unattractive
So... I think this code is nice

AppController

 <?php
class AppController extends Controller {
    public $theme = "";

    public function __get($name) {
        $reuslt = parent::__get($name);
        if (!is_null($reuslt)) {
            return null;
        }

        if ( $this->loadModel($name) ) {
            return $this->$name;
        }
        return null;
    }
}

HogeController

<?php
  class HogeContorller extends AppController {
      public function index() {
          $this->Test->hoge();
      }
  }

no use $use. very nice code!!!

2 Responses
Add your response

not work for me

over 1 year ago ·

@shubh130789
Version of cakephp you're using is?

over 1 year ago ·