Angularjs Yii2+;安格拉斯
我对积分角度和Yii2有问题 我有两个部分:Angularjs Yii2+;安格拉斯,angularjs,.htaccess,yii2,Angularjs,.htaccess,Yii2,我对积分角度和Yii2有问题 我有两个部分: 常规Yii2应用程序 控制器,从actionIndex开始,使用Angular 问题是,当我复制和粘贴url的角度部分,我总是得到404错误。角度配置为 .config(function($routeProvider, $locationProvider) { base = '/construct/'; $routeProvider.when(base+':className', { templateUrl: '/cons
.config(function($routeProvider, $locationProvider) {
base = '/construct/';
$routeProvider.when(base+':className', {
templateUrl: '/construct/builder',
controller: 'BuilderCtrl',
reloadOnSearch: false
}).otherwise({
templateUrl: '/construct/heroes',
controller: 'HeroesCtrl'
});
$locationProvider.html5Mode(true);
});
那么,我怎样才能使HTML5模式下的直接链接工作,以查看正确的页面?
类似“/construct/something”的路径不起作用。
我的访问权限是:
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
由于您正在处理虚拟目录(例如别名/site/“/dir/”),因此必须使用 重写基地/站点/
在apache配置文件中。是否在url管理器的配置中启用了漂亮的url?
Angular与此问题无关,如果您直接访问URL,但URL不起作用,则说明您的配置有问题。htaccess文件看起来正确,但如果您将Web服务器的DocumentRoot和Web应用程序放在单独的文件夹中,如果使用基于unix的操作系统,则首先需要在htaccess文件中设置RewriteBase路径,如下所示:
RewriteEngine on
RewriteBase /~userName/pathToYourYiiProject/web
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
如果从导航器手动加入路径时没有得到结果,则需要首先检查是否激活了漂亮的URL:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
(查看Mihai的链接以获取yii官方文件)
还要检查您的apache配置中是否激活了“重写”模块。要在linux操作系统中启用并加载mod_rewrite,您必须启动以下脚本:
$ cat /etc/apache2/mods-available/rewrite.load
$ sudo a2enmod rewrite
$ ls -al /etc/apache2/mods-enabled/rewrite.load
最后,请记住,最新的Apache版本(2.3.9版)默认为“AllowOverride None”,您必须在/etc/apache2/apache2.conf中将其更改为“AllowOverride All”(同样,linux操作系统中的路径不知道在其他操作系统中是否相同)。重新启动apache服务器并在navigator中手动重新检查路径,如果您得到json格式的结果,那么后端工作正常&angularJs应该能够与之通信。问题是您的Web服务器必须为所有以/construct/开头的路径提供angularJs索引视图。以下是Yii2中URL规则的一个解决方案,它可以实现以下功能: 在config/main.php中
'components' => [
// other components here
'urlManager' => [
// other URL Manager settings here
'rules' => [
'construct/<path:(.*)>'=>'construct/index',
],
],
]
资源:但yii应用程序可以很好地使用这种访问。如果angular的url像我以前注意到的那样,那么问题就存在了。你能告诉我们angular请求并获得404的url吗??
construct
也是目录名还是yii2控制器名?
public function actionIndex($path = '/')
{
// serve your angularJS index page here
}