Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Validation in action contact() #426

Closed

Description

@ondics

I try to understand where the $validator object comes from in src/Contact/ContactController.php

use Yiisoft\Validator\ValidatorInterface;
...
final class ContactController
{
   ...
   public function contact(
       ValidatorInterface $validator,
       ServerRequestInterface $request
   ): ResponseInterface {

}

The action contact is defined in ./config/routes.php:

return [
    // Lonely pages of site
    Route::get('/')
        ->action([SiteController::class, 'index'])
        ->name('site/index'),
    Route::methods([Method::GET, Method::POST], '/contact')
        ->action([ContactController::class, 'contact'])
        ->name('site/contact'),
...

But there is no link to any Validator defined nor any injection of an ValidatorInterface or a model class.

Activity

  1. samdark commented on Dec 30, 2021

    @samdark
    Member

    Yes, it's a new concept if you haven't used DI container in Yii2 (there it was optional). Here you go: https://github.com/yiisoft/docs/blob/master/guide/en/concept/di-container.md It's a draft documentation but, I think, explains it well.

  2. locked and limited conversation to collaborators on Dec 30, 2021
  3. converted this issue into a discussion #427 on Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions