다음은 컨트롤러에서 쉽게 호출 할 수있는 Action Helper의 예입니다.
<?php
class My_Helper_CheckFbLogin extends Zend_Controller_Action_Helper_Abstract
{
public function direct(array $params = array())
{
// you could pass in $params as an array and use any of its values if needed
$request = $this->getRequest();
$view = $this->getActionController()->view;
$fbLogin = new Zend_Session_Namespace('fbLogin'); #Get Facebook Session
if(!$fbLogin->user) {
$this->getActionController()
->getHelper('redirector')
->gotoUrl('/'); #Logout the user
}
return true;
}
}
사용하려면 헬퍼 중개인에게 어디에서 살 것인지 알려줘야합니다.
다음
// Make sure the path to My_ is in your path, i.e. in the library folder
Zend_Loader_Autoloader::getInstance()->registerNamespace('My_');
Zend_Controller_Action_HelperBroker::addPrefix('My_Helper');
가 컨트롤러에서 사용하기 :
public function preDispatch()
{
$this->_helper->CheckFbLogin(); // redirects if not logged in
}
그것은 많은 세부로 이동하지 않지만, Writing Your Own Helpers가 도움이됩니다 여기에 당신이 그렇게 할 수있는 부트 스트랩에 넣어 수있는 예제 코드는 게다가. 당신이 기본 일 대신 확장되는 당신도 baseController을 설정할 수있는 모든 컨트롤러에서이 검사를해야하는 경우
폴더 구조 란 무엇입니까? 컨트롤러/액션/도우미/My_Helper.php? – Uffo
그 예제에서 가져온 프로젝트의 구조는'library/My/Helper/CheckFbLogin.php' – drew010
입니다. 시도해 보겠습니다. ZF 폴더 구조를 이해하지 못했습니다 :) – Uffo