2016-12-02 64 views
2

,因爲我的組件,控制器和模型具有相同的名稱:CakePHP的3組件和模型具有相同的名稱

<?php 
namespace Plug\Controller; 

use Plug\Controller\AppController; 

class SettingController extends AppController 
{ 

    public function initialize(){ 
     parent::initialize(); 
     $this->loadModel('Setting'); 
     $this->loadComponent('Plug.Setting'); 

    } 

我怎麼知道如何引用組件或模型?

回答

1

Check the manual,幾乎所有東西都在那裏。請考慮檢查文檔,在那裏閱讀。

混淆成份

一個常見的設置使用的是類名選項,它可以讓你的別名組件。當你想更換$這個 - 這個功能非常有用>驗證或自定義實現另一種常見的成分參考:

// src/Controller/PostsController.php 
class PostsController extends AppController 
{ 
    public function initialize() 
    { 
     $this->loadComponent('Auth', [ 
      'className' => 'MyAuth' 
     ]); 
    } 
} 

// src/Controller/Component/MyAuthComponent.php 
use Cake\Controller\Component\AuthComponent; 

class MyAuthComponent extends AuthComponent 
{ 
    // Add your code to override the core AuthComponent 
} 
相關問題