Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^246) CHAPTER 16 ■ ADVANCED ZEND FRAMEWORK


/*

Initialize Zend_Filter_Input passing it the
entire getPost() array
*/
$zfi = new Zend_Filter_Input(
$filters,
$validation,
$this->getRequest()->getPost()
);

//If the validators passed, this will be true
if ($zfi->isValid()) {

$dbconfig = array(
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'dbname' => 'demo'
);

$db = Zend_Db::factory('PDO_PGSQL', $dbconfig);

//Create a new Zend_Auth_Adapter
$adapter = new Zend_Auth_Adapter_DbTable(
$db,
'users', //The name of the table
'email', //The name of the 'identity' field
'password', //The name of the 'credential' field
'md5(?)' //SQL function to apply [optional]
);

//Set the identity and credential fields to validated values
$adapter->setIdentity($zfi->email)
->setCredential($zfi->password);

/*
Get an instance of Zend_Auth and
authenticate() using the adapter.
*/
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);

//Check for authentication success
if ($result->isValid()) {

McArthur_819-9C16.fm Page 246 Friday, February 29, 2008 5:07 PM

Free download pdf