2013-04-09 163 views

回答

4

您需要創建自己的模塊並重寫Mage_Cms_PageController控制器(位於app/code/core/Mage/Cms/controllers/PageController.php中)。

這裏是如何做到這一點的教程:http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller

所以你創建你自己的模塊,讓我們說CustomCms/PageAccess。您需要具備以下控制器:

class CustomCms_PageAccess_PageController extends Mage_Cms_PageController 
{ 
    public function viewAction() 
    { 
     $pageId = $this->getRequest()->getParam('id', false); 
     if (Mage::getSingleton('customer/session')->isLoggedIn() || $this->publiclyVisible($pageId)) { 
      parent::viewAction(); // default action 
     } else { 
      $this->_forward('noRoute'); // 404 
     } 
    } 

    /* 
    * this function should be in a helper 
    * !!! Return false if the page should be visible only to logged in users !!! 
    * @return bool 
    */ 
    public function publiclyVisible($pageId) { 
     return true; // here is where you check the page id 
    } 
} 

如果除此之外,你要設置哪些頁面是公開可見的或直接從管理面板保護,您需要在編輯內容管理頁面中添加自定義字段。

這裏是如何做到這一點的教程:http://blog.flexishore.com/2011/08/add-custom-field-to-cms-page/

之後,你需要修改publiclyVisible功能:

public function publiclyVisible($pageId) { 
     $page = Mage::getModel('cms/page')->load(intval($pageId)); 
     // I'm asuming the new field is is_publicly_visible 
     return (bool)$page->getIsPubliclyVisible(); 
    } 

注:

我沒有測試過我鏈接的教程,但通過他們瀏覽,似乎很好。

3

我最近報道了創建a new Magento customer page(自我鏈接)。雖然教程本身對您的需求有點沉重負責,但它確實有一行神奇的代碼來檢查用戶是否登錄。

因此,假設您的「靜態頁面」在Magento環境中運行,下面的PHP代碼應該可以讓您知道要去哪裏。

if(Mage::getSingleton('customer/session')->isLoggedIn()) 
{ 
    var_dump("Is Logged In"); 
} 
else 
{ 
    var_dump("In Not Logged in. Exit or redirect or something."); 
} 
0

對於Magento中的任何頁面,都會有一個MOdule控制器和一個動作函數。

對於控制器操作功能中的特定頁面,您應該應用一個代碼來檢查客戶是否已登錄。 如果沒有登錄重定向到其他頁面。

if(Mage::getSingleton('customer/session')->isLoggedIn()) 
{ 
    continue... 
} 
else 
{ 
    redirect.... 
} 
相關問題