De antemano gracias.
Me da el siguiente error:
Catchable fatal error: Argument 1 passed to Zend_Auth_Adapter_DbTable::__construct() must be an instance of Zend_Db_Adapter_Abstract, instance of Zend_Config_Ini given, called in C:\wamp\www\myfirstzend\application\controllers\Au thController.php on line 34 and defined in C:\wamp\www\myfirstzend\library\Zend\Auth\Adapter\ DbTable.php on line 112
Mi Bootstrap es este:
Código PHP:
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('Chile/Continental');
set_include_path('.' . PATH_SEPARATOR . './library' . PATH_SEPARATOR .'./application/models/' . PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Debug');
Zend_Loader::loadClass('Zend_Auth');
//// load configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// setup database
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
// setup controller
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
//Usar controlador por defecto si url erronea
//$frontController->setParam('useDefaultControllerAlways', true);
$front->setControllerDirectory('./application/controllers');
// run!
//No es la unica manera de manejar errores
//try {
$front->dispatch();
//} catch (Exception $e) {
// require_once("404.php");
//}
Código:
[general] db.adapter = PDO_MYSQL db.config.host = localhost db.config.username = root db.config.password = db.config.dbname = pixelsistema
El AuthController es este:
Código PHP:
class AuthController extends Zend_Controller_Action
{
function init()
{
$this->initView();
$this->view->baseUrl = $this->_request->getBaseUrl();
}
function indexAction()
{
$this->_redirect('/');
}
function loginAction()
{
$this->view->message = '';
if ($this->_request->isPost())
{
// collect the data from the user
Zend_Loader::loadClass('Zend_Filter_StripTags');
$f = new Zend_Filter_StripTags();
$username = $f->filter($this->_request->getPost('user'));
$password = $f->filter($this->_request->getPost('pass'));
if (empty($username))
$this->view->message = 'Please provide a username.';
else
{
// setup Zend_Auth adapter for a database table
Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
$dbAdapter = Zend_Registry::get('config');
/*
Aqui he probado con lo siguiente:
$dbAdapter->db->cinfig->dbname
$dbAdapter->db->adapter
Todo sin éxito y con el mismo error
*/
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('usuario');
$authAdapter->setIdentityColumn('user');
$authAdapter->setCredentialColumn('pass');
// Set the input credential values to authenticate against
$authAdapter->setIdentity($username);
$authAdapter->setCredential($password);
// do the authentication
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid())
{
// success: store database row to auth's storage
// system. (Not the password though!)
$data = $authAdapter->getResultRowObject(null,'pass');
$auth->getStorage()->write($data);
$this->_redirect('/');
}
else
{
// failure: clear database row from session
$this->view->message = 'Login failed.';
}
}
}
$this->view->title = "Log in";
$this->render();
}
function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('/');
}
}