如何在自定義驗證對象中使用組件(自定義或基地像Session
)? (位於Controller/Components/Auth
)?我試過public $components = array('Session', 'name of my custom component');
,但它不起作用。自定義驗證對象中的自定義組件
謝謝...
如何在自定義驗證對象中使用組件(自定義或基地像Session
)? (位於Controller/Components/Auth
)?我試過public $components = array('Session', 'name of my custom component');
,但它不起作用。自定義驗證對象中的自定義組件
謝謝...
由於每CakeBook:
// Pass settings in $components array
public $components = array(
'Auth' => array(
'authenticate' => array(
'name of custom authentication object'
)
)
);
的驗證組件的身份驗證屬性是你陳述的認證對象,你會使用,無論是形式,基本,摘要,或者自定義的。
由於我正在尋找一種方法來自己做這件事,我發現這個問題被問到,我會分享我的發現。
我看了一下BaseAuthenticate :: __ construct(),它看起來像AuthComponent發送控制器的ComponentCollection到每個Autehntication對象。我試着做
$this->Session = $this->_Collection->__get('Session');
$this->Session->write('foo', 'bar');
它的工作,但只是因爲我已經在我的AppController中加載SessionComponent。 ComponentCollection :: __ get()只返回加載的組件。您可能需要查看ComponentCollection類及其父類ObjectCollection,以獲取有關如何使用組件的更多詳細信息。
這是我在驗證階級都:
/**
* Constructor
*
* @param ComponentCollection $collection The Component collection used on this request.
* @param array $settings Array of settings to use.
*/
public function __construct(ComponentCollection $collection, $settings) {
$settings = array_merge($this->settings, $settings);
parent::__construct($collection, $settings);
$this->http = new HttpSocket();
$this->_initComponentCollection();
}
/**
* Initializes all the loaded Components for the Authentication Object.
* Attaches a reference of each component to the Authentication Object.
*
* @return void
*/
protected function _initComponentCollection() {
$components = $this->_Collection->loaded();
if (!empty($components)) {
foreach ($components as $name) {
$this->{$name} = $this->_Collection->__get($name);
}
}
}
這使得僅使用加載的組件的,因爲我不希望加載的所有組件。我將用cakephp打開一張票,看看是否可以向BaseAuthenticate類添加類似的片段。
這不回答這個問題。您正在說明如何加載自定義認證對象。 OP要求的是如何使用自定義身份驗證對象內的組件。 – 2013-05-16 22:43:52