因为我是Zend Framework的完全新手,这可能是一个初学者的问题:
我做了一些教程,现在我已经启动并运行了 ZfcUser (和 ZfcBase )的Zend-Framework skeleton-application 。 到目前为止一切正常,但我想要完成的是登录和注册在Bootstrap-Modal-Dialog中打开。
所以现在我看到./vendor/ZfcUser/config/module.config.php
你可以定义路由,但我不知道该做什么,当我希望整个对话框被“提供”主应用程序的索引时(我猜我需要这个来让应用程序中任何地方的主菜单打开登录对话框。
有人可以帮助我让这个工作吗?我真的不知道如何开始,任何帮助都非常感激:)
最好的问候
答案 0 :(得分:2)
如果你想使用Bootstrap Model进行ZfcUser登录,你需要稍微改变登录方式。
首先将供应商/ ZfcUser / view / user / login.html复制到模块/ [YourModule] /view/zfc-user/user/login.phtml
现在用以下正常按钮替换提交按钮:
<input type="button" value="Sign in" onClick="javascript:verifyLogin(this.form);" />
--
--
<script type="text/javascript">
function verifyLogin(frm)
{
var data = $(frm).serialize();
$.ajax({
type: "POST",
url: "<?php echo $this->url('authurl') ?>",
data: data,
success: function(resp){
alert(resp.status);
},
error: function(resp){
},
dataType: 'json'
});
}
</script>
您应该为YourController / authAction添加authurl路由
在父模板视图中添加用于Bootstrap模型的html:
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Login Box
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<?php echo $this->zfcUserLoginWidget(); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
现在,YourController / authAction代码应该像这样工作:
$request = $this->getRequest();
$data = $request->getPost();
$this->getRequest()->getPost()->set('identity', $data['identity']);
$this->getRequest()->getPost()->set('credential', $data['credential']);
$this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
$this->zfcUserAuthentication()->getAuthService()->clearIdentity();
$adapter = $this->zfcUserAuthentication()->getAuthAdapter();
$adapter->prepareForAuthentication($this->getRequest());
$auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter);
if (!$auth->isValid()) {
//$this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage($this->failedLoginMessage);
$adapter->resetAdapters();
$response_data = array(
'status' => 'Failure'
) ;
}
else
{
$response_data = array(
'status' => 'OK'
) ;
}
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent(json_encode($response_data));
return $response;
答案 1 :(得分:0)
Login Widget viewhelper可能就是你要找的东西。在您想要的.phtml模板中,只需添加viewhelper即可呈现登录表单。
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<?php //Add the Widget to the Modal Body here!?>
<?php echo $this->zfcUserLoginWidget(); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
如果要更改窗口小部件的模板,则需要在zfcuser.global.php
文件夹中编辑/添加../config/autoload/
,并将以下内容更改/取消注释到所需的登录窗口小部件模板。
'user_login_widget_view_template' => 'your_module/whatever/login.phtml',