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!!!
Written by Ryota Mochizuki
Related protips
2 Responses
not work for me
over 1 year ago
·
@shubh130789
Version of cakephp you're using is?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#