我想使用Angularjs从URL中删除#hash $locationProvider.html5Mode(true).
示例:显示地址栏http://localhost/shop而不是http://localhost/#/shop.
一切都运作良好,直到刷新页面.如果我刷新,则会加入以下Laravel路由(在routes.php中定义)
Route::resource('shop', 'ShoppingController')
Run Code Online (Sandbox Code Playgroud)
不是AngularJS路线(在app.js中定义)
$routeProvider.when('/shop', {
templateUrl: 'templates/shop.html',
controller: 'ShoppingController'
});
Run Code Online (Sandbox Code Playgroud)
我的代码:
routes.php(Laravel Routes)
Route::get('/', function() {
return View::make('index');
});
Route::resource('shop', 'ShoppingController');
Run Code Online (Sandbox Code Playgroud)
app.js(AngularJS路线)
var app = angular.module('shoppingApp',['ngRoute','SharedServices']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/shop', {
templateUrl: 'templates/shop.html',
controller: 'ShoppingController'
});
$routeProvider.otherwise({ redirectTo: '/' });
$locationProvider.html5Mode(true);
});
Run Code Online (Sandbox Code Playgroud)
我的目录结构:
Project
/app
/...
/views
-index.php (single page application file)
-routes.php (Laravel routes)
/public
/...
/js
-angular.js
-app.js
-index.php (Laravel index file)
Run Code Online (Sandbox Code Playgroud)
尝试的解决方案:
重写htaccess文件,以便将所有请求重定向到index.php(单页应用程序文件,AngularJS将从该文件中接管路由).问题:通过这种方式,Laravel路由(Route :: resource('shop','ShoppingController'); - 与数据库交互所必需的)变得无法访问AngularJS $ …
我有三张桌子:
author (columns: aut_id, aut_name)
book (columns: book_id, book_title)
authorbook (linking table, columns: aut_id, book_id)
Run Code Online (Sandbox Code Playgroud)
每个作者都可以与一本或多本书相关联.
每本书都可以与一位或多位作者联系.
我想根据名称和作者的确切数量来选择一本书.
表结构:
author
aut_id | aut_name
1 Aname
2 Bname
3 Cname
book
book_id | book_title (the titles are identical on purpose)
1 Atitle
2 Atitle
3 Atitle
authorbook
aut_id | book_id
1 1
1 2
2 2
1 3
2 3
3 3
Run Code Online (Sandbox Code Playgroud)
这是我的代码(我遗漏了作者表以便更好地澄清):
SELECT authorbook.book_id
FROM authorbook
INNER JOIN book
ON authorbook.book_id = book.book_id
WHERE book_title='Atitle'
AND FIND_IN_SET (authorbook.aut_id,'1,2')
GROUP BY …Run Code Online (Sandbox Code Playgroud)