-- maxarbos <[EMAIL PROTECTED]> wrote
(on Thursday, 10 July 2008, 12:53 PM -0700):
> 
> I think I got it.
> 
> I needed to change the resource name to caplital 'Test'
> 
> So I just need to add the check within every method?
> Seems a bit susceptible to errors.

The other possibility is to make those methods protected and prefix them
with a '_', and add proxying via __call():

    protected function _echoHello()
    {
        echo 'Hello!';
    }

    public function __call($method, $args)
    {
        if (method_exists($this, '_' . $method)) {
            if (!$this->acl->isAllowed($this->user, __CLASS__, $method)) {
                throw new Exception('Access denied');
            }
            return call_user_func_array(array($this, '_' . $method), $args);
        }

        throw new Exception(sprintf('Invalid method "%s"', $method));
    }

Any method that doesn't need ACL checks can then simply be declared
public.

This _will_ have a performance hit (both from overloading and from using
call_user_func_array()), but it will automate things.


> maxarbos wrote:
> > 
> > still getting the same error:
> > 
> > denied
> > Fatal error: Uncaught exception 'Zend_Acl_Exception' with message
> > 'Resource 'Test' not found' 
> > in /xxx/Zend/Acl.php:297 
> > Stack trace: 
> > #0 /xxx/Zend/Acl.php(691): Zend_Acl->get('Test') 
> > #1 /xxxx/admin/Test.php(24): 
> > Zend_Acl->isAllowed('guest', 'Test', 'echoHello') 
> > #2 /xxx/admin/index.php(50): Test->echoHello() 
> > #3 {main} thrown in /xxx/Zend/Acl.php on line 297
> > 
> > 
> > 
> > vRandom wrote:
> >> 
> >> Move this 
> >> 
> >> require_once 'Test.php';
> >> $test = new Test($acl);
> >> 
> >> under
> >> 
> >> $acl->allow('member', 'test');
> >> 
> >> Terre
> >> 
> >> 
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Is-it-possible-to-use-Zend_ACL-without-MVC-tp18385583p18390545.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
> 

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to