zenframework2 route跳转后为什么域名会变成localhost 在线等紧急感谢大家先

etracer 2014-12-11 02:04:36
zenframework2 route跳转后为什么域名会变成localhost
我访问 http://xxx.com/webcav/application/index/login 跳转后变成了
http://localhost/webcav/application/index/login
(同一个action处理显示和登陆,所以要跳转到同样的地址)

处理代码如下

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;
}



module.config.php


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(
),
),
),
),
),
),
),

最可能出现问题的地方view

<?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();

?>
...全文
348 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
etracer 2014-12-11
  • 打赏
  • 举报
回复
来人给分,自己解决了

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧