小编DB9*_*B93的帖子

Laravel验证器抛出异常而不是重定向

升级到Laravel 5.2后,我遇到了laravel验证器的问题.当我想验证控制器中的数据时,例如使用此代码.

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class ContactController extends Controller
{
    public function storeContactRequest(Request $request)
    {
        $this->validate($request, [
            '_token' => 'required',
            'firstname' => 'required|string'
            'lastname' => 'required|string'
            'age' => 'required|integer',
            'message' => 'required|string'
        ]);

        // Here to store the message.
    }
}
Run Code Online (Sandbox Code Playgroud)

但不知何故,当我输入无效数据时,它不会将我重定向回上一页并向会话中闪现一些消息,但它会触发异常并给我一个500错误页面.

这是我得到的例外.我在文档中读到ValidationException是新的而不是HttpResponseException但我不知道它是否与此有关.

[2016-01-05 11:49:49] production.ERROR: exception 'Illuminate\Foundation\Validation\ValidationException' with message 'The given data failed to pass validation.' in /home/vagrant/Code/twentyre-webshop/vendor/laravel/framework/src/Illuminate/Foundation/Validation/ValidatesRequests.php:70
Run Code Online (Sandbox Code Playgroud)

当我使用一个单独的请求类时,它只会重定向回错误消息.在我看来,只有控制器中使用的验证方法才会受到此行为的影响.

php validation laravel php-5.6 laravel-5

12
推荐指数
2
解决办法
1万
查看次数

6502间接访问模式

我的问题是关于6502汇编语言的。我正在尝试使用此网站https://skilldrick.github.io/easy6502/进行学习。

关于寻址模式的主题。我不了解间接寻址模式。请参见下面的源代码示例。

LDA #$01
STA $f0
LDA #$cc
STA $f1
JMP ($00f0) ;dereferences to $cc01
Run Code Online (Sandbox Code Playgroud)

为什么JMP ($00f0)取消引用到$cc01而不是$01cc

我的记忆看起来像这样

00f0: 01 cc 00 00 00 00 00 00 00 00 00 00 00 00 84

在这里,您看到00f0以开始,01然后是跟随,cc因此对我来说,跳转指令将取消引用是更合乎逻辑的$01cc,但是为什么这会以某种方式逆转?

6502

4
推荐指数
1
解决办法
187
查看次数

使用PHP连接到棘轮Websocket服务器

我在后端运行Ratchet WebSocketServer,一切正常。

<?php

require '../vendor/autoload.php';

use Ratchet\WebSocket\WsServer;
use Ratchet\Http\HttpServer;

$wsServer = new WsServer(new Chat());
$wsServer->disableVersion(0);

$server = \Ratchet\Server\IoServer::factory(
    new HttpServer(
        $wsServer
    ),
    8080
);

$server->run();
Run Code Online (Sandbox Code Playgroud)

但是我想使用简单的php脚本连接到websocket,以将消息发送到服务器。

$host = 'ws://localhost';  //where is the websocket server
$port = 8080;
$local = "http://example.com";  //url where this script run 
$data = "first message";  //data to be send

$head = "GET / HTTP/1.1"."\r\n".
    "Upgrade: WebSocket"."\r\n".
    "Connection: Upgrade"."\r\n".
    "Origin: $local"."\r\n".
    "Host: $host:$port"."\r\n".
    "Sec-WebSocket-Key: asdasdaas76da7sd6asd6as7d"."\r\n".
    "Content-Length: ".strlen($data)."\r\n"."\r\n";

//WebSocket handshake
$sock = fsockopen($host, $port);
fwrite($sock, $head ) or …
Run Code Online (Sandbox Code Playgroud)

php sockets php-socket websocket ratchet

3
推荐指数
1
解决办法
5057
查看次数

Crystal函数不等待用户输入

晶体中的获取功能不等待用户输入.当我启动我的控制台应用程序时,它立即输出如下所示的错误.这是说给in_array函数的第二个参数是Nil,但程序甚至不要求用户输入.

在此输入图像描述

我的代码如下所示.

# Only alice and bob are greeted.
def in_array(array : Array, contains : String)
    array.each { |e|
        if e == contains
            return true;
        end
    }

    return false;
end

allowed = ["Alice", "Bob"]

puts "Please enter your name to gain access."
name = gets

isAllowed = in_array(allowed, name)

if isAllowed
    puts "You can enter the secret room"
else
    puts "You are not allowed to enter the secret room."
end
Run Code Online (Sandbox Code Playgroud)

我的代码的新版本包括?和read_line

# Only alice and bob are greeted.
allowed = …
Run Code Online (Sandbox Code Playgroud)

crystal-lang

3
推荐指数
1
解决办法
430
查看次数