別のコントローラー内でコントローラー関数を使用する必要があります。でも作りたくない
$Myother = new MyotherController();
そのコントローラーのメソッドを使用するたびに。すべてのメソッドで「新しい」ものを作成しないように、コントローラーを初期化するにはどうすればよいですか?
私はこれを見つけました、それはこのように書いています:
App::import('Controller', 'Pages');
class UsersController extends AppController {
var $Pages;
function beforeFilter() {
$this->Pages =& new PagesController; /*Loads the class*/
$this->Pages->constructClasses(); /*Loads the model associations, components, etc. of the Pages controller*/
}
function index() {
$this->Pages->index();
}
}
これは適切な方法ですか、それともより良い方法はありますか?