Just an idea.

 

This is something I've quickly thrown together, not tested - so it's
probably got a few errors in it, but should be relatively simple to fix J

 

Let me know if you get it working J

 

<?php

 

class sfRequiredIfPermissionValidator extends sfValidator

{

 

  public function execute(&$value, &$error)

  {

    $required = $this->getContext()->getRequest()->getParameter(

      $this->getParameterHolder()->get('required')); 

      

    $permission = $this->getParameterHolder()->get('permission');

 

    if (!isset($required)) return TRUE; // it has no value, no need to
validate

    

if (!($this->getContext()->getUser()->hasPermission($permission) &&
!empty($required)))

    {

      $error = $this->getParameterHolder()->get('error'); 

      return FALSE; 

    }

 

    return TRUE;

  }

 

  public function initialize($context, $parameters = null)

  {

    // initialize parent

    parent::initialize($context);

 

    // set defaults

    $this->getParameterHolder()->set('error', 'required error');

    $this->getParameterHolder()->add($parameters);

 

    return TRUE;

  }

}

 

From: symfony-users@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of Paul Wiegers
Sent: 02 March 2008 09:25
To: symfony-users@googlegroups.com
Subject: [symfony-users] Re: Credentials for fields and validation

 

On Sun, Mar 2, 2008 at 9:45 AM, Haris Zukanovic' <[EMAIL PROTECTED]>
wrote:


I think that action is never reached when there are validation errors.
There may be other places where to insert such a hack :)


I think I could end up with a number of hacks that could provide all kinds
of workarounds. My real question is: it would look like simple, basic
functionality, because fo the nature of symfony you would exepect it to be
used for online database systems. Virtualy all of those systems need some
kind of rights-management. In most cases this will involve showing fields
only to certain users. Then you run in to this problem. Of course, you could
create different partials (that would be my first path I'd take), but I
would like to know that is 'te real' symfony way of doing this......?

thanks for any insights!

Paul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to