I am at wits end with this, where most of the examples could be
instructive, they use phrases such as:
"Other details, such as how the authentication service is queried,
have been omitted for brevity"
Which these details are precisely what is ambiguous (at least to me).
I have a login form which takes username and password and passes them
to the login action called processAction. Within processAction, the
request is validated for POST and variables etc etc. Then comes the
actual authentication to check the database and verify the 'identity'
of the user.
The following code is giving me 'fatal error Call to a member function
isValid() on a non-object':
// Get authentication adapter to check input variables
$adapter = $this->getAuthAdapter($form->getValues());
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
Then later isValid is called on $result like so: $result->isValid()
and blamo I get the error.
Now .. getAuthAdapter instantiates the following class:
class MyAuthAdapter implements Zend_Auth_Adapter_Interface
{
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
public function authenticate()
{
$db_config = array('host' => '127.0.0.1', 'username' =>
'ioforgec_zend', 'password' => 'Pa55w0rD', 'dbname' =>
'ioforgec_iofdb');
try
{
$db = Zend_Db::factory('Pdo_Mysql', $db_config);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
print "// perhaps a failed login credential, or perhaps the
RDBMS is not running\n";
} catch (Zend_Exception $e) {
print "// perhaps factory() failed to load the specified
Adapter class\n";
}
// Attempt to use fetchAll() - The first argument to this method
is a string containing a SELECT statement
// The second argument to fetchAll() is an array of values to
substitute for parameter placeholders in the SQL statement
$sql = "SELECT * FROM users WHERE username = ? AND password = ?";
$result = $db->fetchAll($sql, array($this->username, $this->password));
// Return Zend_Auth_Result Object to determine success or
failure of authenticate attempt
if ($result[0]['auth']) { return Zend_Auth_Result::SUCCESS; }
return Zend_Auth_Result::FAILURE;
}
Ok .. so I used the Zend_Auth_Result because as I read it turns out
thats what the isValid() function is expecting. Other places I read I
need to call the Zend_Auth method Authenticate without any changes,
while others say I need to instantiate a Zend_Auth_Adapter and over
write the authenticate call with my own DB selects, etc.
What is going on here? How can I get so confused? Im following
directions (Or so I thought) from a tutorial on the zendframework
site:
http://weierophinney.net/matthew/archives/165-Login-and-Authentication-with-Zend-Framework.html
Could I get a little re-alignment? Thank you ;0)