public function listuserAction()
{
$db = Zend_Db_Table::getDefaultAdapter();
//$db = $this->_db;
$select = $db->select();
$select->from('user', array('*'));
$test = $db->fetchAll($select);
print_r($test); die;
}
-----------
login
<div><?php echo $this->fmessages; ?></div>
<form name="<?php echo $this->form->getAttrib('name'); ?>" id="<?php echo $this->form->getAttrib('id'); ?>" action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>">
<ul>
<li>
<label>Username: <?php echo $this->form->user_name; ?></label>
</li>
<li>
<label>Password: <?php echo $this->form->password; ?></label>
</li>
<li>
<?php echo $this->form->login; ?>
</li>
</ul>
</form>
-----
public function init()
{
//Initialize action controller here
$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
$registry = Zend_Registry::getInstance();
$this->_em = $registry->entitymanager;
if($this->_flashMessenger->getMessages())
{
$fmsgArr = $this->_flashMessenger->getMessages();
$this->fmsg = $fmsgArr[0];
}
$this->view->fmessages = $this->fmsg;
$this->request = Zend_Controller_Front::getInstance()->getRequest();
$this->contUrl = $this->request->getBaseUrl().'/'.$this->request->getModuleName().'/'.$this->request->getControllerName();
}
public function getUserMapperObj()
{
if(is_null($this->userObj))
{
$this->userObj = new User_Model_userRegisterMapper($this->_em);
}
return $this->userObj;
}
--------
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity())
{
$this->_redirect('/user/login');
}
Wednesday, February 5, 2014
zend list page
Zend auth checking
public function authAction()
{
$request = $this->getRequest();
$registry = Zend_Registry::getInstance();
$auth = Zend_Auth::getInstance();
$DB = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
$authAdapter->setTableName('user')
->setIdentityColumn('user_name')
->setCredentialColumn('password');
// Set the input credential values
$uname = $request->getParam('user_name');
$paswd = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($paswd));
// Perform the authentication query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid())
{
$data = $authAdapter->getResultRowObject(null,'password');
$auth->getStorage()->write($data);
$this->_redirect('user/index/listuser');
}
else
{
$this->_flashMessenger->addMessage($this->view->translator('user_invalid_login'));
$this->_redirect('user/index/login');
}
}
zend db connection
resources.db.adapter = "PDO_MYSQL"
resources.db.isDefaultAdapter = true
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = "zend_learn"
----------
{
$form = new User_Form_loginForm();
$this->view->form = $form;
}
-----------
class User_Form_loginForm extends Zend_Form
{
public function init()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$action = $request->getBaseUrl().'/'.$request->getModuleName().'/'.$request->getControllerName().'/auth';
$this->setMethod('post')
->setName('frmlogin')
->setAttrib('id', 'frmlogin')
->setAction($action);
$username = $this->createElement('text', 'user_name');
$username->setAttrib('class', 'required')
->setAttrib('minlength', 4)
->setAttrib('maxlength', 15)
//->addFilter(array('StripTags', 'StringTrim'))
->addFilter('StripTags')
->addFilter('StringTrim')
->setRequired(true);
$password = $this->createElement('password', 'password');
$password->setAttrib('class', 'required')
->setRequired(true);
$submit = $this->createElement('submit', 'login');
$this->addElements(array($username, $password, $submit));
}
}
Subscribe to:
Posts (Atom)