4,251
社区成员
发帖
与我相关
我的任务
分享
public function loginAction()
{
$flashMessenger=$this->flashMessenger();
$message='';
if($flashMessenger->hasMessages())
{
$message_array=$flashMessenger->getMessages();
$message = $message_array[0];
}
$form =new UserForm();
$form-> get('submit')->setValue('繝ュ繧ー繧、繝ウ');
$request=$this->getRequest();
if($request->isPost())
{
$this->getTranslator()->addTranslationFile('phparray','/var/www/zend2/vendor/ZF2/resources/languages/ja/Zend_Validate.php');
$user=new User();
$form->setInputFilter($user->getInputFilter());
$form->setData($request->getPost());
if($form->isValid())
{
$user->exchangeArray($form->getData());
$auth =new Auth();
if($auth->login($user,$this->getDBAdapter()))
{
$this->flashMessenger()->addMessage('繝ュ繧ー繧、繝ウ縺悟ョ御コ・@縺セ縺励');
return $this->redirect()->toRoute('application',array(
'controller'=>'user',
'action'=>'index'
));
}else{
$message="繝ュ繧ー繧、繝ウ縺ォ螟ア謨励@縺セ縺励";
}
}
}
$values=array(
'form'=>$form,
'message'=>$message,
);
$view =new ViewModel($values);
return $view;
}
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Segment',
'options' => array(
'route' => '/application[/:controller[/:action[/:id]]]',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action[/:id]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
<?php if(strlen($message)):?>
<div style='padding:4px;margin:4px;border:dotted 2px #448800; background:#ddffdd;'>
<?php echo $message;?>
</div>
<?php endif;?>
<?php
$form=$this->form;
$form->setAttribute('action',$this->url(
'application',array('controller'=>'index','action'=>'login')
));
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('email'));
echo $this->formRow($form->get('password'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>