【发布时间】:2012-03-11 03:48:24
【问题描述】:
我正在尝试使我的自定义过滤器工作...
我的 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/Filter/
我找到了有关设置命名空间和添加路径的文档,但我什么都做不了...
有人对我的问题有有效的解决方案吗?这将是高度赞赏!
提前致谢!
【问题讨论】:
标签: php zend-framework frameworks filter