title: How to handle Exception when Zend_Acl is On? it gives Resource 'default::error::error' not found'
body: <p>i've implemeted the Zend_Acl and its seems to be working.my resources are links :</p>
  
  <blockquote>
    <p>module_name . "::" . controller_name . "::" . action_name;</p>
  </blockquote>
  
  <p>i've added something in my code that's breaking and it seems that's i'm redirected to the usual error page but that the Acl comes in saying </p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'default::error::error' not found' in F:\work\php\zendworkspace\myproject\library\Zend\Acl.php on line 365</p>
  </blockquote>
  
  <p>i have added the <code>default::error::error</code> to the resources but the error is still the same.
  when i remove the code that's breaking the whole thing works again.
  So i would definitely have the same error when something breaks in my code.</p>
  
  <p>I would like to find out how to solve this. thanks for reading and  sharing your experience.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>the code to implement that is kind of long. this is a db driven ACL with doctrine.
  i've modified <a href="http://blog.davidjclarke.co.uk/database-driven-zend-acl-tutorial-part-two.html" rel="nofollow">this tutorial</a> to implement mine.i've cut out the myACL class, looks the same as the one in the tutorial, and the ACL plugin is kind of the same.i've registerd it in the application.ini.</p>
  
  <pre><code>// this class build all the roles and resouces and add 2 users to 2 differents roles and so on
  class CMS_Util_AddResourcesAndRoles {
  
  private $arrModules = array();
  private $arrControllers = array();
  public $arrActions = array();
  private $arrIgnores = array('.', '..', '.svn');
  
  public function BuildMCAArrays() {
      $this-&gt;BuildModuleArray();
      $this-&gt;BuildControllersArray();
      $this-&gt;BuildActionArray();
      return $this;
  }
  
  public function CheckData() {
      if (count($this-&gt;arrModules) &lt; 1)
          throw new CMS_Exception_ResourceNotFound("No Modules found ..");
  
      if (count($this-&gt;arrControllers) &lt; 1)
          throw new CMS_Exception_ResourceNotFound("No Controllers found ..");
  
      if (count($this-&gt;arrActions) &lt; 1)
          throw new CMS_Exception_ResourceNotFound("No Actions found ..");
  }
  
  public function BuildModuleArray() {
      $cmsApplicationModules = opendir(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules');
      while (false !== ($cmsFile = readdir($cmsApplicationModules))) {
          if (!in_array($cmsFile, $this-&gt;arrIgnores)) {
              if (is_dir(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $cmsFile)) {
                  $this-&gt;arrModules[] = $cmsFile;
              }
          }
      }
      closedir($cmsApplicationModules);
      return $this-&gt;arrModules;
  }
  
  public function BuildControllersArray() {
      if (count($this-&gt;arrModules) &gt; 0) {
          foreach ($this-&gt;arrModules as $strModuleName) {
              $cmsControllerFolder = opendir(APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR . $strModuleName . DIRECTORY_SEPARATOR . "controllers");
              while (false !== ($cmsFile = readdir($cmsControllerFolder))) {
                  if (!in_array($cmsFile, $this-&gt;arrIgnores)) {
                      if (preg_match('/Controller/', $cmsFile)) {
   //     if(strtolower(substr($cmsFile, 0, -14)) != "error")
   //     $this-&gt;arrControllers[$strModuleName][] = strtolower(substr($cmsFile, 0, -14));
                          $this-&gt;arrControllers[$strModuleName][] = strtolower (substr($cmsFile, 0, -14));
                      }
                  }
              }
              closedir($cmsControllerFolder);
          }
      }
      return $this-&gt;arrControllers;
  }
  
  private function BuildActionArray() {
  //        $arrMethods = array();
      if (count($this-&gt;arrControllers) &gt; 0) {
          foreach ($this-&gt;arrControllers as $strModule =&gt; $strController) {
              foreach ($strController as $strController) {
                  if ($strModule == "default") {
                      $strClassName = ucfirst($strController . 'Controller');
                  } else {
                      $strClassName = ucfirst($strModule) . '_' . ucfirst($strController . 'Controller');
                  }
  
                  if (!class_exists($strClassName)) {
                      Zend_Loader::loadFile(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $strModule . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . ucfirst($strController) . 'Controller.php');
                  }
  
                  $objReflection = new Zend_Reflection_Class($strClassName);
                  $arrMethods = $objReflection-&gt;getMethods();
                  foreach ($arrMethods as $arrMethod) {
                      if (preg_match('/Action/', $arrMethod-&gt;name)) {
                          $this-&gt;arrActions[$strModule][$strController][] = substr($arrMethod-&gt;name, 0, -6);
    //  $this-&gt;arrActions[$strModule][$strController][] = substr($this-&gt;_camelCaseToHyphens($objMethods-&gt;name), 0, -6);
                      }
                  }
              }
          }
      }
      return $this-&gt;arrActions;
  }
  
  private function _camelCaseToHyphens($string) {
      if ($string == 'currentPermissionsAction') {
          $found = true;
      }
      $length = strlen($string);
      $convertedString = '';
      for ($i = 0; $i &lt; $length; $i++) {
          if (ord($string[$i]) &gt; ord('A') &amp;&amp; ord($string[$i]) &lt; ord('Z')) {
              $convertedString .= '-' . strtolower($string[$i]);
          } else {
              $convertedString .= $string[$i];
          }
      }
      return strtolower($convertedString);
  }
  
  public function WriteResourcesToDb() {
      $this-&gt;BuildMCAArrays();
      $this-&gt;CheckData();
      $resources = array();
  
      foreach ($this-&gt;arrModules as $strModuleName) {
          if (array_key_exists($strModuleName, $this-&gt;arrControllers)) {
              foreach ($this-&gt;arrControllers[$strModuleName] as $strControllerName) {
                  if (array_key_exists($strControllerName, $this-&gt;arrActions[$strModuleName])) {
                      foreach ($this-&gt;arrActions[$strModuleName][$strControllerName] as $strActionName) {
                          $res = new CMS_Model_Resource();
                          $res-&gt;module_name = $strModuleName;
                          $res-&gt;controller_name = $strControllerName;
                          $res-&gt;action_name = $strActionName;
                          $res-&gt;name = $strModuleName . "_" . $strControllerName . "_" . $strActionName;
                          $resources[] = $res;
  
                          $this-&gt;PersistResource($resources);
                      }
                  }
              }
          }
      }
      return $this;
  }
  
  private function PersistResource(array $resourceobject) {
      try {
          $collection = new Doctrine_Collection("CMS_Model_Resource");
          foreach ($resourceobject as $resource) {
              $collection-&gt;add($resource);
          }
          $collection-&gt;save();
      } catch (Exception $exc) {
          echo $exc-&gt;getTraceAsString();
      }
  }
  
  
  public function WriteRoleAndUserstoDb(){
      $guest = new CMS_Model_Role();
      $guest-&gt;name = "guest";
      $guest-&gt;description = "simple user";
      $guest-&gt;canbedeleted = true;
  
      $member = new CMS_Model_Role();
      $member-&gt;name = "member";
      $member-&gt;description = "member with limited privileges,can access member reserved resources";
      $member-&gt;canbedeleted = true;
  
      $publisher = new CMS_Model_Role();
      $publisher-&gt;name = "publisher";
      $publisher-&gt;description = "publisher with publish an unpublished privileges";
      $publisher-&gt;canbedeleted = true;
  
      $manager = new CMS_Model_Role();
      $manager-&gt;name = "manager";
      $manager-&gt;description = "manager with privileges to publish, to unpublish, general manager of the site";
      $manager-&gt;canbedeleted = true;
  
      $admin = new CMS_Model_Role();
      $admin-&gt;name = "administrator";
      $admin-&gt;description = "admin with all privileges";
      $admin-&gt;canbedeleted = false;
  
      $superadmin = new CMS_Model_Role();
      $superadmin-&gt;name = "superadmin";
      $superadmin-&gt;description = "superadmin to rule them all";
      $superadmin-&gt;canbedeleted = false;
  
  
      $superadmin-&gt;Parents[0] = $admin;
      $admin-&gt;Parents[0] = $manager;
      $manager-&gt;Parents[0] = $publisher;
      $publisher-&gt;Parents[0] = $member;
      $member-&gt;Parents[0] = $guest;
  
  
      $adminname = new CMS_Model_User();
      $adminname-&gt;id = CMS_Util_Common::uuid();
      $adminname-&gt;first_name = "adminname";
      $adminname-&gt;last_name = "surname";
      $adminname-&gt;full_name = "adminname surname";
      $adminname-&gt;password = "password";
      $adminname-&gt;email = "mister@somemail.com";
      $adminname-&gt;is_active = true;
      $adminname-&gt;is_verified = true;
      $adminname-&gt;username ="superadmin";
      $adminname-&gt;Role = $superadmin;
  
      $adminname2 = new CMS_Model_User();
      $adminname2-&gt;id = CMS_Util_Common::uuid();
      $adminname2-&gt;first_name = "adminname2";
      $adminname2-&gt;last_name = "adminsurname";
      $adminname2-&gt;email="shallom@someemail.fr";
      $adminname2-&gt;full_name = "adminname2 adminsurname";
      $adminname2-&gt;password = "adminadmin";
      $adminname2-&gt;is_active = true;
      $adminname2-&gt;is_verified = true;
      $adminname2-&gt;username ="admin";
      $adminname2-&gt;Role = $admin;
  
      $thepublisher = new CMS_Model_User();
      $thepublisher-&gt;id = CMS_Util_Common::uuid();
      $thepublisher-&gt;first_name = "one publisher";
      $thepublisher-&gt;last_name = "lastname";
      $thepublisher-&gt;full_name = "something something";
      $thepublisher-&gt;email = "user@somegmail.com";
      $thepublisher-&gt;password = "password";
      $thepublisher-&gt;username = "publisher";
      $thepublisher-&gt;is_active = true;
      $thepublisher-&gt;is_verified = true;
      $thepublisher-&gt;Role = $publisher;
  
  
  
      $conn = Doctrine_Manager::getInstance()-&gt;getCurrentConnection();
      $conn-&gt;flush();
      return $this;
  }
  
  
  public function AssignResourcesToRoles(){
  
      $guestcollection = new Doctrine_Collection("CMS_Model_RoleResource");
      $guestroles = Doctrine_Core::getTable("CMS_Model_Role")-&gt;GetRoleByName("guest");
      $defautresources = Doctrine_Core::getTable("CMS_Model_Resource")-&gt;GetResourceByModule("default");
      foreach($defautresources as $resource){
          $guestroleresource = new CMS_Model_RoleResource();
          $guestroleresource-&gt;Role = $guestroles;
          $guestroleresource-&gt;Resource = $resource;
          $guestcollection-&gt;add($guestroleresource);
      }
  
      $guestcollection-&gt;save();
  
      $admincollection = new Doctrine_Collection("CMS_Model_RoleResource");
      $adminroles = Doctrine_Core::getTable("CMS_Model_Role")-&gt;GetRoleByName("superadmin");
      $adminresources = Doctrine_Core::getTable("CMS_Model_Resource")-&gt;GetResourceByModule("admin");
  
  
      foreach($adminresources as $resource){
          $adminroleresource = new CMS_Model_RoleResource();
          $adminroleresource-&gt;Role = $adminroles;
          $adminroleresource-&gt;Resource = $resource;
          $admincollection-&gt;add($adminroleresource);
      }
  
      $admincollection-&gt;save();
      return $this;
  }
  
  
  public function SetAclUp(){
      $this-&gt;WriteResourcesToDb();
      $this-&gt;WriteRoleAndUserstoDb();
      $this-&gt;AssignResourcesToRoles();
      return $this;
   }
  }
  </code></pre>
  
  <p>as you can see i've granted all links under default to role <code>guest</code> meaning <code>guest</code> can see the <code>default::error::error page</code> when there is a problem.  </p>
  
  <p>I can also assure you that, when nothing is broken in my code, i can login with the <code>publisher</code> credential and get bounced anytime i'm trying to go to the admin panel. </p>