Mostrando entradas con la etiqueta zend framework. Mostrar todas las entradas
Mostrando entradas con la etiqueta zend framework. Mostrar todas las entradas

Cómo utilizar Zend_Auth_Adapter con Web Services

<?
class My_Auth_Adapter implements Zend_Auth_Adapter_Interface {

    const OK_RESPONSE = 'OK';
    const KO_RESPONSE = 'KO';

    private $_username = '';
    private $_password = '';
    private $_data = null;

    public function setIdentity($username) {
        $this->_username = $username;
    }

    public function setCredential($password) {
        $this->_password = $password;
    }

    /**
     * Authenticate the user
     * 
     * @return Zend_Auth_Result 
     */
    public function authenticate() {
        $endpointLoginAuthor = Zend_Registry::get('config')->endpoint->userService->loginAuthor;

        $client = new Zend_Rest_Client($endpointLoginAuthor);
        $client->username($this->_username);
        $client->password($this->_password);

        $response = $client->get();
        
        $authenticated = ($response->ResponseDescription == $this::OK_RESPONSE);
        $authResult = Zend_Auth_Result::FAILURE;

        $authMessages = array();

        if ($authenticated){
            // user is authenticated, overwrite the auth result:
            $authResult = Zend_Auth_Result::SUCCESS;
            $this->_data = $response->Author;
        } else {
            // Couldn't authenticate the user, set a message:
            $authMessages[] = 'Datos de acceso inválidos.';
        }

        // return the result:
        return new Zend_Auth_Result( $authResult, $this->_username, $authMessages );

    }

    /**
     *
     * @param <type> $returnColumns
     * @param <type> $omitColumns
     * @return <type> SimpleXMLObject
     */
     public function getResultRowObject($returnColumns = null, $omitColumns = null){
        // If no data is set, return false:
        if (!$this->_data) {
            return false;
        }

        return $this->_data;
    }
}

?>


Cómo setear desde un Controller variables de un Zend_Layout

En el controller:
 

class MyController extends Zend_Controller_Action {
    public function init() {
        $this->_helper->layout->getView()->myVar = 'Value'; 
    }
}

En el layout.phtml

<? echo $this->myVar; ?>

MAMP carga muy lento cuando se llama a Zend_Session::start();

El session handler tiene algún problema al intentar guardar las sessiones en disco.

Entonces se puede utilizar Zend para utilizar otro adapter y por ejemplo guardar las sesiones en una BD.

// Comment
$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'        =>'localhost',
    'username'    => 'dbuser',
    'password'    => '****',
    'dbname'    => 'mydb'
));

//you can either set the Zend_Db_Table default adapter
//or you can pass the db connection straight to the save handler $config
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$config = array(
    'name'           => 'session',
    'primary'        => 'id',
    'modifiedColumn' => 'modified',
    'dataColumn'     => 'data',
    'lifetimeColumn' => 'lifetime'
);

//create your Zend_Session_SaveHandler_DbTable and
//set the save handler for Zend_Session
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));

// start session
Zend_Session::start();