douguanya4248 2017-05-19 20:07
浏览 43
已采纳

修剪应用程序错误:尊重\验证\验证程序

I get this error when trying to Validate my OrderForm.php. If someone followed Codecourse Shopping Cart Tutorial you may know why I get this error. Here is my code in some of my files that I think is most relevant to this error and of course the error.

Error:

Message: Class 'Respect\Validation\Validator' not found
File: PATH/cart/app/Validation/Forms/OrderForm.php on 13


I will also post this image of my Directory Folders: Directory Folder Image


OrderForm.php

<?php

namespace Cart\Validation\Forms;


use Respect\Validation\Validator as v;

class OrderForm
{
    public static function rules()
    {
        return [
            'email' => v::email(),
            'name' => v::alpha(' '),
            'address1' => v::alnum(' -'),
            'address2' => v::optional(v::alnum(' -')),
            'city' => v::alnum(' '),
            'postal_code' => v::alnum(' '),
        ];
    }
}

Validator.php

<?php

namespace Cart\Validation;

use Cart\Validation\Contracts\ValidatorInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Respect\Validation\Exceptions\NestedValidationException;

class Validator implements ValidatorInterface
{
    protected $errors = [];

    public function validate(Request $request, array $rules)
    {
        foreach ($rules as $field => $rule) {
            try {
                $rule->setName(ucfirst($field))->assert($request->getParam($field));
            } catch (NestedValidationException $e) {
                $this->errors[$field] = $e->getMessages();
            }
        }

        $_SESSION['errors'] = $this->errors;

        return $this;
    }

    public function fails()
    {
        return !empty($this->errors);
    }
}

ValidatorInterface.php

<?php

namespace Cart\Validation\Contracts;

use Psr\Http\Message\ServerRequestInterface as Request;

interface ValidatorInterface
{
    public function validate(Request $request, array $rules);
    public function fails();

}

Edit: I just want to say that I changed:
use Respect\Validation\Validator as v;
to
use Cart\Validation\Validator as v;

And then I get a completely new error so that did that work.

  • 写回答

2条回答 默认 最新

  • duandong1869 2017-05-19 20:20
    关注

    Well it tells you where the error is:

    Message: Class 'Respect\Validation\Validator' not found

    Path to that class is not valid, or that file is not on that path. I'm not completely sure but if you write it like you did use Respect\Validation\Validator as v; the final path will be current namespace plus that path Cart\Validation\Forms\Respect\Validation\Validator.

    File: PATH/cart/app/Validation/Forms/OrderForm.php on 13

    This second part is just were it triggered the error, on line 13 'email' => v::email(),.

    Edit: I just saw that image, the path should be use \App\Validation\Validator

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图