本文将介绍如何在我的web.php中修复路由而不会在搜索时出现404错误?的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于angularjs–即使
本文将介绍如何在我的 web.php 中修复路由而不会在搜索时出现 404 错误?的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于angularjs – 即使图像出现,为什么我的ng-src会出现404错误?、angularjs – 如何在我的应用程序中修复angular.js路由?、c# – 创建两个不会在ASP.NET MVC中生成404错误的路由的问题、Jquery select2如何在搜索时调用自定义函数的知识。
本文目录一览:- 如何在我的 web.php 中修复路由而不会在搜索时出现 404 错误?
- angularjs – 即使图像出现,为什么我的ng-src会出现404错误?
- angularjs – 如何在我的应用程序中修复angular.js路由?
- c# – 创建两个不会在ASP.NET MVC中生成404错误的路由的问题
- Jquery select2如何在搜索时调用自定义函数
如何在我的 web.php 中修复路由而不会在搜索时出现 404 错误?
如何解决如何在我的 web.php 中修复路由而不会在搜索时出现 404 错误??
我的 CustomerController 中有这个
public function search(Request $req){
$search = $req->get(''search-customer'');
$customer = Customer::where(''first_name'',''like'',''%''.$search.''%'')->paginate(5);
return view(''customers.index'',[''guests'' => $customer]);
}
这是我在路由 web.PHP 中的代码
Route::get(''/customers/search'',[CustomerController::class,''search''])->name(''customers.search'');
这个在我的 index.blade.PHP
<div>
<form action="{{ route(''customers.search'') }}" method="GET">
<input type="text" name="search-customer" placeholder="Enter a name to search">
<input type="submit" value="Search">
</form>
<a href="{{ route(''customers.index'') }}"><button>Refresh</button></a>
</div>
这是我的完整 web.PHP
<?PHP
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\GuestController;
use App\Http\Controllers\HomeController;
use App\Models\Guest;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get(''/'',function () {
return view(''welcome'');
});
// Customer Controller
Route::get(''/customers'',''index''])->name(''customers.index'');
Route::get(''/customers/add'',''create''])->name(''customers.create'');
Route::get(''/customers/{id}'',''show''])->name(''customers.show'');
Route::post(''/customers'',''store''])->name(''customers.store'');
Route::post(''/customers/update'',''update''])->name(''customers.update'');
Route::get(''/customers/search'',''search''])->name(''customers.search'');
Route::delete(''/customers/{id}'',''destroy''])->name(''customers.destroy'');
// Guest Controller
Route::get(''/guests'',[GuestController::class,''index''])->name(''guests.index'');
Route::get(''/guests/add'',''create''])->name(''guests.create'');
Route::get(''/guests/{id}'',''show''])->name(''guests.show'');
Route::post(''/guests'',''store''])->name(''guests.store'');
Route::post(''/guests/update'',''update''])->name(''guests.update'');
Route::get(''/search'',''search''])->name(''guests.search'');
Route::delete(''/guests/{id}'',''destroy''])->name(''guests.destroy'');
Auth::routes([''verify'' => true]);
Route::get(''/home'',[HomeController::class,''index''])->name(''home'');
Route::get(''/email/verify'',function () {
return view(''auth.verify-email'');
})->middleware(''auth'')->name(''verification.notice'');
Route::get(''/email/verify/{id}/{hash}'',function (EmailVerificationRequest $request) {
$request->fulfill();
return redirect(''/home'');
})->middleware([''auth'',''signed''])->name(''verification.verify'');
- 所以我的问题是我也有一个 GuestController,它也有一个搜索框,我的 web.PHP 中的访客路由是
Route::get(''/search'',''search''])->name(''guests.search'');
并且在我搜索访客时它工作正常,同时在客户中我收到一个错误,显示未找到 404。 - 这是我在文本框中搜索客户表的内容时得到的链接
http://127.0.0.1:8000/customers/search?search-customer=Paul
谢谢各位
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
angularjs – 即使图像出现,为什么我的ng-src会出现404错误?
< img style =“width:100px”ng-src =“{{absolutePath}} customImages / {{currentBook.idcode}}.png”/>
找到并显示正常,但在Firebug控制台中,我收到此错误:
NetworkError:404 Not Found – http://localhost/learntracker/customImages/.png“
好像这是在变量存在之前执行的.
此HTML代码存在于< div ng-cloak ng-app =“mainModule”>内.和ng-cloak我理解在变量存在之前停止任何执行.
为什么会出现此错误,如何抑制它?
angularjs – 如何在我的应用程序中修复angular.js路由?
Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file://file:///Users/patutinskijfedor/Desktop/firebase/WILLY/www/' cannot be created in a document with origin 'null'.
我在互联网上读到了这个问题,并意识到我的问题在于角度路由.它看起来像这样(文件app.js):
angular.module('SCBI',['SCBI.controllers','ngRoute']).config(function($routeProvider,$locationProvider){ $locationProvider.html5Mode(true); $routeProvider.when('/teachers',{ templateUrl: 'teachers.html'}); $routeProvider.when('/teachers/:id',{templateUrl: 't.html',controller: 'TeachersListController'}); $routeProvider.when('/',{templateUrl: 'authorization.html',controller: 'AuthorizationController'}); $routeProvider.otherwise({redirectTo:'/'}); });
所以问题可能在于html5Mode.我的问题是:如何在app.js中修复路由?该项目的完整代码如下:https://github.com/patut/SCBI.
解决方法
c# – 创建两个不会在ASP.NET MVC中生成404错误的路由的问题
routes.MapRoute("Default","{controller}/{action}",new {controller = "Home",action = "Index"} ); routes.MapRoute("Second","{*catchall}",action = "Index",id = UrlParameter.Optional} );
当我使用与第一条路线不匹配的不存在的路径时,它工作正常,像这样 –
但如果确实如此,那么我有以下几点 –
要么
我理解它发生的原因.然而,目前,我只能找到“某种”解决方案.将以下代码添加到web.config文件 –
<customErrors mode="On"> <error statusCode="404" redirect="~/Home/Index"/> </customErrors>
但是,我不认为这是解决这个问题的最佳方法.因为,据我所知,它只是捕获所有错误并将其重定向到正确的路径,而不实际使用路由.所以我认为我不需要这种全局处理.
那么有人可以给我一个提示,或者为我提供一个很好的解决方案.谢谢.
解决方法
>项目中不存在控制器或操作.
>如果传递了“id”,则它必须存在于action方法中.
路线
我使用约束来做到这一点. AFAIK,无法对可选参数使用约束.这意味着为了使id参数可选,您需要3条路线.
routes.MapRoute( name: "DefaultWithID",url: "{controller}/{action}/{id}",defaults: new { controller = "Home",action = "Index" },constraints: new { action = new ActionExistsConstraint(),id = new ParameterExistsConstraint() } ); routes.MapRoute( name: "Default",url: "{controller}/{action}",constraints: new { action = new ActionExistsConstraint() } ); routes.MapRoute( name: "Second",url: "{*catchall}",action = "Index" } );
ActionExistsConstraint
public class ActionExistsConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext,Route route,string parameterName,RouteValueDictionary values,RouteDirection routeDirection) { if (routeDirection == RouteDirection.IncomingRequest) { var action = values["action"] as string; var controller = values["controller"] as string; var thisAssembly = this.GetType().Assembly; Type[] types = thisAssembly.GetTypes(); Type type = types.Where(t => t.Name == (controller + "Controller")).SingleOrDefault(); // Ensure the action method exists return type != null && type.getmethod(action) != null; } return true; } }
ParameterExistsConstraint
public class ParameterExistsConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext,RouteDirection routeDirection) { if (routeDirection == RouteDirection.IncomingRequest) { var action = values["action"] as string; var controller = values["controller"] as string; var thisAssembly = this.GetType().Assembly; Type[] types = thisAssembly.GetTypes(); Type type = types.Where(t => t.Name == (controller + "Controller")).SingleOrDefault(); var method = type.getmethod(action); if (type != null && method != null) { // Ensure the parameter exists on the action method var param = method.GetParameters().Where(p => p.Name == parameterName).FirstOrDefault(); return param != null; } return false; } return true; } }
Jquery select2如何在搜索时调用自定义函数
可以在Ajax请求的URL参数中设置一个函数
let js_mySelect = {
init: function () {
mySelect.select2({
ajax: {
url: function() { console.log("Test"); return 'myUrl'},dataType: 'json'
}
});
},
};
今天的关于如何在我的 web.php 中修复路由而不会在搜索时出现 404 错误?的分享已经结束,谢谢您的关注,如果想了解更多关于angularjs – 即使图像出现,为什么我的ng-src会出现404错误?、angularjs – 如何在我的应用程序中修复angular.js路由?、c# – 创建两个不会在ASP.NET MVC中生成404错误的路由的问题、Jquery select2如何在搜索时调用自定义函数的相关知识,请在本站进行查询。
本文标签: