我所有的CSS和JavaScript文件都在AppAsset中,我将它们加载到布局文件中。在我的登录页面上,我不想使用布局,所以我使用renderPartial()方法呈现登录视图文件。在执行此操作时,我创建了一个新的LoginAsset文件,并使用它来注册登录视图,但我的CSS和JS仍然没有加载。我还尝试使用AppAsset包注册登录视图,但它也没有加载CSS和JS。我有什么地方做错了吗?在我的控制器上使用renderPartial时,如何加载我的资源包?
发布于 2016-02-11 06:59:10
Hi @Zack你的问题是你没有指定结束正文和结束页面的位置。我解决了我的问题,将这些代码添加到我的页面底部。
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>发布于 2016-11-23 18:30:30
作为Pavel said,您应该使用renderAjax()。请参阅下面的说明。
renderPartial()的输出是由视图生成的和平的超文本标记语言,没有任何CSS和JS:
<div class="container">
<input type="text" id="loginform-username" class="form-control" name="LoginForm[username]">
<input type="password" id="loginform-password" class="form-control" name="LoginForm[password]">
<button type="submit" class="btn btn-primary btn-block" name="login-button">Log in</button>
</div>但是renderAjax()将视图 assets中所有注册的中的CSSs和JSs添加到输出中:
<link href="/assets/f1759119/css/bootstrap.css" rel="stylesheet">
<div class="container">
<input type="text" id="loginform-username" class="form-control" name="LoginForm[username]">
<input type="password" id="loginform-password" class="form-control" name="LoginForm[password]">
<button type="submit" class="btn btn-primary btn-block" name="login-button">Log in</button>
</div>
<style>
...
</style>
<script>
...
</script>
<script src="/assets/13aa7b5d/jquery.js"></script>
<script src="/assets/302a2946/yii.js"></script>
<script src="/assets/302a2946/yii.activeForm.js"></script>PS。我认为正确的方法是为登录表单创建单独的布局,并使用常用的render()方法。
https://stackoverflow.com/questions/29465226
复制相似问题