繁体   English   中英

[Laravel 5.1]自定义路线显示白页(空白)

[英][Laravel 5.1]Custom routes display a white (blank) page

我当前在Win 10计算机上使用XAMPP(PHP 5.6.21)。

我正在从.net站点迁移到laravel。 到目前为止,我几乎没有问题,以前的大多数问题都来自经验不足。 但我找不到此错误的解决方案。

routes.php

//Operaciones
Route::resource('operaciones', 'OperacionesController');
//Ruta al cierre de Operaciones
Route::any('operaciones/cerrar', ['as' => 'operaciones/cerrar', function(){
dd('asdasd');
}]);

资源路由工作正常,但是第二条路由为我带来了白页(空白)

如果我在网络浏览器中放了什么都没关系

如果我放

http://localhost:8080/mutualv0/public/operaciones/asdasdasd

白页,如果我放

http://localhost:8080/mutualv0/public/operaciones/cerrar

再次...

但是,如果你尝试这个

http://localhost:8080/mutualv0/public/operaciones2

NotFoundHttpException

我的日志中没有任何内容,我安装了laravel链接检查器,并且没有向我抛出任何错误...我只是不知道该怎么办...

更新

我试过了

php artisan route:cache

这给我带来了一个错误“无法准备路由[operaciones / cerrar]进行序列化。使用闭包”

所以我改变了路线

Route::get('operaciones/cerrar', ['as' => 'operaciones/cerrar', 'uses' => 'OperacionesController@cerrar']);

并向OperacionesController添加一个函数

public function cerrar()
{
    dd('hello');
}

我使用php artisan服务,但仍然存在相同的错误...(空白)页面...

更新2

我使用的链接是

<a href="{{ route('operaciones/cerrar') }}" class="btn btn-success" role="button">Cerrar operaciones seleccionadas</a>

我试图将链接更改为

<a href="{{ route('cerraroperaciones') }}" class="btn btn-success" role="button">Cerrar operaciones seleccionadas</a>

并更新路线至

Route::any('operaciones/cerrar', [
    'as' => 'cerraroperaciones', 'uses' => ' OperacionesController@cerrar'
]);

但这给我抛出了一条未定义路线[cerraroperaciones]

我也尝试做一个link_to_action ,并在OperacionesController @ cerrar上抛出“未定义的动作”

更新3

上载到GitHub

https://github.com/diegorosano/mutual

假设“ mulualv0”目录是顶级目录,那么您应该使用以下命令访问您的网站:

http:// localhost:8080 / mutualv0 / operaciones / cerrar

顶层目录是项目的根目录。 它包括应用程序,引导程序,配置等目录。

请勿在链接中包含“公共”目录。 您的服务器应配置为服务公共目录。

首先,尝试运行此工匠命令

php artisan route:cache

如果不起作用,请检查是否是XAMPP问题。

您需要将Public文件夹设置为Rootdirectory ,(如果这对您Rootdirectory ,那就是问题所在)

1)禁用XAMPP,(如果您使用的是DB,请仅在XAMPP中禁用php)

2)将CMD&Cd打开到应用程序的根目录(您可以在其中找到.env文件。.etc)3)使用artisan php artisan serve运行artsan serve的php内置服务器,

这将为您显示一个链接,尝试它是否有效http://localhost:8000/operaciones/cerrar

编辑

将路线置于资源路线上方

    Route::any('operaciones/cerrar', [
        'as' => 'cerraroperaciones', 'uses' => ' OperacionesController@close',
    ]);
    Route::resource('operaciones', 'OperacionesController');

图片

在此处输入图片说明

结果

在此处输入图片说明

  1. 嘿,只需更改您的config / 'env' => env('APP_ENV', 'development'), 'debug' => env('APP_DEBUG', true),即可找到错误。
  2. 您的第二条路线对您没有任何影响OperacionesController这条路线将分开工作。

    Route::any('operaciones/cerrar', ['as' => 'operaciones/cerrar', function(){ dd('asdasd'); }]);

  3. 如果要从OperacionesController调用函数cerrar ,请执行以下操作

    Route::any('operaciones/cerrar', [ 'as' => 'operaciones/cerrar', 'uses' => ' OperacionesController @cerrar' ]);

但是这里你也使用了相同的路径,所以这里没有使用'as'

编辑:

我不知道出什么问题了,但是您直接使用它会调用您的函数:

Route::any('cerraroperaciones',  OperacionesController@cerrar');

解决方案是从Laravel 5.1升级到5.2 ...现在适用于所有路线。 全部

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM