मैं सिम्फोनी में custom constraint बनाने 3बाधा गुण या टिककर खेल
मैं त्रुटि
बाधा अनुप्रयोग \ बंडल \ MyBundle \ सत्यापनकर्ता \ प्रतिबन्ध है \ कोड संपत्तियों पर नहीं रखा जा सकता कोशिश पर नहीं रखा जा सकता या टिककर खेल
<?php
// vendor/app/mybundle/Validator/Constraints/Code.php
namespace App\Bundle\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
class Code extends Constraint
{
public $message = 'Error validate message!!!';
public function validatedBy()
{
return 'alias_name';
}
public function getTargets()
{
//return self::CLASS_CONSTRAINT; // error "The constraint cannot be put on properties or getters"
return array(self::PROPERTY_CONSTRAINT, self::CLASS_CONSTRAINT); // working, but $value is a STRING!!!
}
}
मेरे विक्रेता/ऐप्स/mybundle/सत्यापनकर्ता/प्रतिबन्ध/CodeValidator.php
<?php
// vendor/app/mybundle/Validator/Constraints/CodeValidator.php
namespace App\Bundle\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class CodeValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
$value->getId(); // this code not working, because $value is STRING!!
$this->context->buildViolation($constraint->message)
->atPath('code')
->addViolation();
}
}
जहाँ मैं एक गलती की है?
इससे मदद नहीं मिली :( – Neokortex
मैं अपना बदलता हूं, @ चालासर फिर से दिखता हूं। कृपया – Neokortex
मैंने आपकी ज़रूरत के अनुरूप बदलाव किए हैं। – chalasr