我試圖讓我的自定義過濾器的工作......Zend框架的自定義過濾器在自己的libary目錄
我在AuthController下面的代碼:
<?php
public function loginAction()
{
// Get db var
$db = $this->_getParam('db');
// Load loginform
$loginForm = new Application_Form_Auth_Login();
// Form posted?
if ($loginForm->isValid($_POST))
{
// Setup adapter
$adapter = new Zend_Auth_Adapter_DbTable(
$db,
'users',
'username',
'password'
);
// Set identity and credential
$adapter->setIdentity($loginForm->getValue('username'));
$adapter->setCredential($loginForm->getValue('password'));
// Setup Zend_Auth and try to authenticate the user
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
// If authentication succeed
if ($result->isValid())
{
$this->_helper->FlashMessenger('Inloggen geslaagd');
$this->_redirect('/');
return;
}
else
{
$this->_helper->FlashMessenger('Inloggen geslaagd');
}
}
$this->view->loginForm = $loginForm;
}
?>
形式的代碼:
<?php
class Application_Form_Auth_Login extends Zend_Form
{
/**
* Default_Form_Auth_Login::init()
*
* Form which authenticates guests
*
* @return void
*/
public function init()
{
$this->setMethod('post');
$this->addElement('text', 'username', array(
'label' => 'Gebruikersnaam:',
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('password', 'password', array(
'label' => 'Wachtwoord:',
'required' => true,
'filters' => array('Pcw_Filter_Hash')
));
$this->addElement('hash', 'formToken', array(
'salt' => 'unique'
));
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Inloggen',
));
}
}
我的自定義過濾器的代碼是:
<?php
class Pcw_Filter_Hash implements Zend_Filter_interface
{
/**
* HashFilter::filter()
*
* @param string $value
* @return
*/
public function filter($value)
{
return hash('sha512', $value);
}
}
以這種方式使用時,我不斷收到此消息: 消息:在註冊表中找不到名爲'Pcw_Filter_Hash'的插件;使用的路徑:Zend_Filter_:Zend公司/過濾/
我發現文檔中關於設置的命名空間和添加路徑,但我不能得到任何工作......
任何人不會有我的問題一個可行的解決方案?這將非常讚賞!
在此先感謝!
謝謝你,但是在application.ini中定義Pcw對我來說不起作用。 這樣做的確如此:Zend_Loader_Autoloader :: getInstance(); $裝載機> registerNamespace( 'Pcw_'); 我沒有複製你寫我的表單元素的風格。 謝謝你的時間! – 2012-02-20 20:17:11