Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Added usage exemple for the URL validator #4632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Basic Usage
Acme\BlogBundle\Entity\Author:
properties:
bioUrl:
- Url: ~
- Url:
message: The url "{{ value }}" is not a valid url.
protocols: [http, https]

.. code-block:: php-annotations

Expand All @@ -37,7 +39,10 @@ Basic Usage
class Author
{
/**
* @Assert\Url()
* @Assert\Url(
* message = "The url '{{ value }}' is not a valid url",
* protocols = {"http", "https"}
* )
*/
protected $bioUrl;
}
Expand All @@ -52,7 +57,13 @@ Basic Usage

<class name="Acme\BlogBundle\Entity\Author">
<property name="bioUrl">
<constraint name="Url" />
<constraint name="Url">
<option name="message">The url "{{ value }}" is not a valid url.</option>
<option name="protocols">
<value>http</value>
<value>https</value>
</option>
</constraint>
</property>
</class>
</constraint-mapping>
Expand All @@ -69,7 +80,10 @@ Basic Usage
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url());
$metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
'message' => 'The url "{{ value }}" is not a valid url.',
'protocols' => array('http', 'https'),
)));
}
}

Expand Down