2011-07-02 8 views
0

「リソース「のデフォルト::エラー::エラー」が見つかりませんリンクされていますそれは破壊だとそれはそれは私が通常のエラーページにリダイレクトしていますようだが、ACLはZend_Aclがオンの場合の例外処理方法は?私は私のコードで何かを追加しました</p> <blockquote> <p>module_name . "::" . controller_name . "::" . action_name;</p> </blockquote> <p>:それは私がZend_Aclではをimplemeted、そのworking.my資源であるように思わまし

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

を言うに来ることを私はリソースへdefault::error::errorを追加したが、エラーはまだ同じです。 全体を壊しているコードを削除すると、再び機能します。 私は間違いなく私のコードで何かが壊れたときに同じエラーが発生します。

私はこの問題を解決する方法を見つけるしたいと思います。あなたの経験を読んで共有することに感謝します。

編集:それは一種の長いです実装する

コード。これは、教義のあるDB主導のACLです。 私はチュートリアルのものと同じに見えますし、ACLプラグインはのapplication.iniでそれをregisterd same.i'veの一種である、mine.i'veはmyACLクラスを切り出す実装するthis tutorialを変更しました。

// 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->BuildModuleArray(); 
    $this->BuildControllersArray(); 
    $this->BuildActionArray(); 
    return $this; 
} 

public function CheckData() { 
    if (count($this->arrModules) < 1) 
     throw new CMS_Exception_ResourceNotFound("No Modules found .."); 

    if (count($this->arrControllers) < 1) 
     throw new CMS_Exception_ResourceNotFound("No Controllers found .."); 

    if (count($this->arrActions) < 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->arrIgnores)) { 
      if (is_dir(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $cmsFile)) { 
       $this->arrModules[] = $cmsFile; 
      } 
     } 
    } 
    closedir($cmsApplicationModules); 
    return $this->arrModules; 
} 

public function BuildControllersArray() { 
    if (count($this->arrModules) > 0) { 
     foreach ($this->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->arrIgnores)) { 
        if (preg_match('/Controller/', $cmsFile)) { 
//  if(strtolower(substr($cmsFile, 0, -14)) != "error") 
//  $this->arrControllers[$strModuleName][] = strtolower(substr($cmsFile, 0, -14)); 
         $this->arrControllers[$strModuleName][] = strtolower (substr($cmsFile, 0, -14)); 
        } 
       } 
      } 
      closedir($cmsControllerFolder); 
     } 
    } 
    return $this->arrControllers; 
} 

private function BuildActionArray() { 
//  $arrMethods = array(); 
    if (count($this->arrControllers) > 0) { 
     foreach ($this->arrControllers as $strModule => $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->getMethods(); 
       foreach ($arrMethods as $arrMethod) { 
        if (preg_match('/Action/', $arrMethod->name)) { 
         $this->arrActions[$strModule][$strController][] = substr($arrMethod->name, 0, -6); 
    // $this->arrActions[$strModule][$strController][] = substr($this->_camelCaseToHyphens($objMethods->name), 0, -6); 
        } 
       } 
      } 
     } 
    } 
    return $this->arrActions; 
} 

private function _camelCaseToHyphens($string) { 
    if ($string == 'currentPermissionsAction') { 
     $found = true; 
    } 
    $length = strlen($string); 
    $convertedString = ''; 
    for ($i = 0; $i < $length; $i++) { 
     if (ord($string[$i]) > ord('A') && ord($string[$i]) < ord('Z')) { 
      $convertedString .= '-' . strtolower($string[$i]); 
     } else { 
      $convertedString .= $string[$i]; 
     } 
    } 
    return strtolower($convertedString); 
} 

public function WriteResourcesToDb() { 
    $this->BuildMCAArrays(); 
    $this->CheckData(); 
    $resources = array(); 

    foreach ($this->arrModules as $strModuleName) { 
     if (array_key_exists($strModuleName, $this->arrControllers)) { 
      foreach ($this->arrControllers[$strModuleName] as $strControllerName) { 
       if (array_key_exists($strControllerName, $this->arrActions[$strModuleName])) { 
        foreach ($this->arrActions[$strModuleName][$strControllerName] as $strActionName) { 
         $res = new CMS_Model_Resource(); 
         $res->module_name = $strModuleName; 
         $res->controller_name = $strControllerName; 
         $res->action_name = $strActionName; 
         $res->name = $strModuleName . "_" . $strControllerName . "_" . $strActionName; 
         $resources[] = $res; 

         $this->PersistResource($resources); 
        } 
       } 
      } 
     } 
    } 
    return $this; 
} 

private function PersistResource(array $resourceobject) { 
    try { 
     $collection = new Doctrine_Collection("CMS_Model_Resource"); 
     foreach ($resourceobject as $resource) { 
      $collection->add($resource); 
     } 
     $collection->save(); 
    } catch (Exception $exc) { 
     echo $exc->getTraceAsString(); 
    } 
} 


public function WriteRoleAndUserstoDb(){ 
    $guest = new CMS_Model_Role(); 
    $guest->name = "guest"; 
    $guest->description = "simple user"; 
    $guest->canbedeleted = true; 

    $member = new CMS_Model_Role(); 
    $member->name = "member"; 
    $member->description = "member with limited privileges,can access member reserved resources"; 
    $member->canbedeleted = true; 

    $publisher = new CMS_Model_Role(); 
    $publisher->name = "publisher"; 
    $publisher->description = "publisher with publish an unpublished privileges"; 
    $publisher->canbedeleted = true; 

    $manager = new CMS_Model_Role(); 
    $manager->name = "manager"; 
    $manager->description = "manager with privileges to publish, to unpublish, general manager of the site"; 
    $manager->canbedeleted = true; 

    $admin = new CMS_Model_Role(); 
    $admin->name = "administrator"; 
    $admin->description = "admin with all privileges"; 
    $admin->canbedeleted = false; 

    $superadmin = new CMS_Model_Role(); 
    $superadmin->name = "superadmin"; 
    $superadmin->description = "superadmin to rule them all"; 
    $superadmin->canbedeleted = false; 


    $superadmin->Parents[0] = $admin; 
    $admin->Parents[0] = $manager; 
    $manager->Parents[0] = $publisher; 
    $publisher->Parents[0] = $member; 
    $member->Parents[0] = $guest; 


    $adminname = new CMS_Model_User(); 
    $adminname->id = CMS_Util_Common::uuid(); 
    $adminname->first_name = "adminname"; 
    $adminname->last_name = "surname"; 
    $adminname->full_name = "adminname surname"; 
    $adminname->password = "password"; 
    $adminname->email = "[email protected]"; 
    $adminname->is_active = true; 
    $adminname->is_verified = true; 
    $adminname->username ="superadmin"; 
    $adminname->Role = $superadmin; 

    $adminname2 = new CMS_Model_User(); 
    $adminname2->id = CMS_Util_Common::uuid(); 
    $adminname2->first_name = "adminname2"; 
    $adminname2->last_name = "adminsurname"; 
    $adminname2->email="[email protected]"; 
    $adminname2->full_name = "adminname2 adminsurname"; 
    $adminname2->password = "adminadmin"; 
    $adminname2->is_active = true; 
    $adminname2->is_verified = true; 
    $adminname2->username ="admin"; 
    $adminname2->Role = $admin; 

    $thepublisher = new CMS_Model_User(); 
    $thepublisher->id = CMS_Util_Common::uuid(); 
    $thepublisher->first_name = "one publisher"; 
    $thepublisher->last_name = "lastname"; 
    $thepublisher->full_name = "something something"; 
    $thepublisher->email = "[email protected]"; 
    $thepublisher->password = "password"; 
    $thepublisher->username = "publisher"; 
    $thepublisher->is_active = true; 
    $thepublisher->is_verified = true; 
    $thepublisher->Role = $publisher; 



    $conn = Doctrine_Manager::getInstance()->getCurrentConnection(); 
    $conn->flush(); 
    return $this; 
} 


public function AssignResourcesToRoles(){ 

    $guestcollection = new Doctrine_Collection("CMS_Model_RoleResource"); 
    $guestroles = Doctrine_Core::getTable("CMS_Model_Role")->GetRoleByName("guest"); 
    $defautresources = Doctrine_Core::getTable("CMS_Model_Resource")->GetResourceByModule("default"); 
    foreach($defautresources as $resource){ 
     $guestroleresource = new CMS_Model_RoleResource(); 
     $guestroleresource->Role = $guestroles; 
     $guestroleresource->Resource = $resource; 
     $guestcollection->add($guestroleresource); 
    } 

    $guestcollection->save(); 

    $admincollection = new Doctrine_Collection("CMS_Model_RoleResource"); 
    $adminroles = Doctrine_Core::getTable("CMS_Model_Role")->GetRoleByName("superadmin"); 
    $adminresources = Doctrine_Core::getTable("CMS_Model_Resource")->GetResourceByModule("admin"); 


    foreach($adminresources as $resource){ 
     $adminroleresource = new CMS_Model_RoleResource(); 
     $adminroleresource->Role = $adminroles; 
     $adminroleresource->Resource = $resource; 
     $admincollection->add($adminroleresource); 
    } 

    $admincollection->save(); 
    return $this; 
} 


public function SetAclUp(){ 
    $this->WriteResourcesToDb(); 
    $this->WriteRoleAndUserstoDb(); 
    $this->AssignResourcesToRoles(); 
    return $this; 
} 
} 

あなたは私は問題がある場合default::error::error pageを見ることができguestを意味役割guestにデフォルトの下にあるすべてのリンクを許可している見ることができるように。

私のコードで何も壊れていない場合は、publisherの資格情報でログインして、管理パネルに行くときにいつでもバウンスすることができます。

答えて

0

最も人気のあるエラーは、任意のインスタンスのリソースを追加していないということです。

+0

こんにちはgtOkAi私は 'guest'.theyなどのリソースは、すべてのデータベースからロードされているユーザ/インスタンスが付与されていることを示すためにポストを編集しました。 もし私があなたが「どんなインスタンスのためのリソースも追加していない」ということを理解していないのであれば、それについてもっと詳しく説明してください。応答してくれてありがとう –

関連する問題

 関連する問題