0

I'm using this validation code in actions.class.php to validate the input ,

$name = $this->getRequestParameter('title');    
if (!$name)
{
    $this->getRequest()->setError('The name field cannot be left blank');
    return false;
}

But encounter errors like

You must set "compat_10" to true if you want to use this method which is deprecated.

in error log. After getting this error, I set compat_10 to true in settings.yml, but still get the same error.

1
  • 2
    Are you not using the form framework? You can set validators on form fields using that. Commented Apr 21, 2011 at 12:09

3 Answers 3

1

The $this->getRequest()->setError() method is only available in symfony 1.0 and 1.1, strating from symfony 1.2 the validator behaviour and all the error handling in the actions was removed in order to be more in line with the new form framework.

I'm guessing you're using a version 1.2 to 1.4, in which case the method you're trying to use is deprecated and you have to enable the compat_10 plugin for that. I see that you have enabled it but since it's behavior comes from a plugin you must ensure that you have sfCompat10Plugin enabled in your ProjectConfiguration::configure() method.

As a side note, it's best to use the validators form the form framework for this kind of errors.

Sign up to request clarification or add additional context in comments.

Comments

0

Depending on how hard you want to fail you can do one of the following:

  • Throw a sfException... This shows the generic 500 error message.
  • forward to 404. For example when your title is part of the url or an other sort of selection parameter. There's a handy way to do this: $this->forward404Unless($name, 'No title provided').
  • Set your message to template var $this->errorMessage = '...'; and then return the error view return sfView::ERROR, and show a nice message in the template actionError.php.

(I'd probably go for the second)

Comments

0

You can use exceptional handling for error handling

try {
 $this->getRequest()
 } catch (\Doctrine\ORM\NoResultException $e) {
 return null;
}

1 Comment

This is for doctrine2 and / or symfony 2, OP talks about symfony 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.