Hello,

The documentation for Zend_Auth does not mention anything about MVC, and
you can use the code examples there as a guide:

http://framework.zend.com/manual/en/zend.auth.html

For requests that must be authenticated, you could do something like the
following:

require_once 'Zend/Auth.php';
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
    // Identity exists; get it
    $identity = $auth->getIdentity();
} else {
    // Set up the authentication adapter
    $authAdapter = new MyAuthAdapter($username, $password);

    // Attempt authentication, saving the result
    $result = $auth->authenticate($authAdapter);

    if (!$result->isValid()) {
        // Authentication failed; print the reasons why
        foreach ($result->getMessages() as $message) {
            echo "$message\n";
        }
        // You can also switch on $result->getCode(), which returns the
type of authentication failure that corresponds to a Zend_Auth constant
    } else {
        // Authentication succeeded; the identity ($username) is stored
in the session
        // $result->getIdentity() === $auth->getIdentity()
        // $result->getIdentity() === $username
    }
}

All this is straight from the documentation, but keep in mind that your
business rules will likely drive exactly how you will utilize any
authentication mechanisms.

If you have suggestions on how to improve the documentation, we would be
happy to receive them. Good documentation is important and also hard
work. :)

Hope this helps!

Best regards,
Darby

Kexiao Liao wrote:
> Hi All,
>    I need to use Zend_Auth class for my current web application. My current
> web application does not support MVC stuff. So in my case, I only need to
> use Zend_Auth class for the web authentication, Is there any good
> Example/Demo codes to integrate Zend_Auth class into current application?
> Thanks in advance.
> 
>    

Reply via email to