u는 ZF의 기존 구성 요소를 사용하여 몇 가지 새로운 플러그인에서 그들을 결합 할 수 있습니다 : 내 경우에는 ZF 구조에 저장
1) 새로운 ZF 플러그인 : /library/My/Controller/Plugin/ActionHistory.php
final class My_Controller_Plugin_ActionHistory extends Zend_Controller_Plugin_Abstract
{
/** @var bool flag indicating whether current action has been already logged */
private $dispatched = false;
/**
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function pushStack(Zend_Controller_Request_Abstract $request) {
$storage = $this->getStorage();
$storage->stack[] = $request;
// limit the depth of the stack
if (count($storage->stack) > $this->getMaxDepth()) {
array_shift($storage->stack);
}
// mark current action as dispatched (influences getBacklink())
$this->dispatched = true;
}
public function popStack() {
$storage = $this->getStorage();
return array_pop($storage->stack);
}
/**
* Returns request to previous action (not current).
*
* @return Zend_Controller_Request_Abstract|null
*/
public function getBacklink() {
$storage = $this->getStorage();
$depth = count($storage->stack);
// points to top of the stack
$backlinkIndex = $depth - 1;
if ($this->dispatched) {
// current action has been already logged, "backlink" is second from the top
--$backlinkIndex;
}
return ($backlinkIndex >= 0 ? $storage->stack[$backlinkIndex] : null);
}
/**
* Returns stack with performed actions
* @return array
*/
public function getStack() {
return $this->getStorage()->stack;
}
/**
* @return Zend_Session_Namespace
*/
private function getStorage() {
static $storage = null;
if ($storage === null) {
$storage = new Zend_Session_Namespace(get_class($this), true);
if (!is_array($storage->stack)) {
// initialize stack if needed
$storage->stack = array();
}
}
return $storage;
}
/**
* Returns maximal depth of the action history
* @return int
*/
private function getMaxDepth() {
return 3;
}
}
2)이 코드를 어딘가에 배치하여 이력을 스택에 넣습니다. 예 : 내역 만 사용할 수 있습니다. 응용 프로그램에 대한 로깅과 협력하거나 모든 기록을 저장할 수 있습니다.그것은 당신에 따라 달라집니다
// this code is example of usage in another ZF controller plugin class
$actionHistory = Zend_Controller_Action_HelperBroker::getStaticHelper("ActionHistory");
if ($actionHistory) {
// $this => instance of Zend_Controller_Plugin_Abstract
$actionHistory->pushStack($this->getRequest());
}
3) 당신이 그런 행동 기록을 처리 할 경우 다음 U 어떤 컨트롤러에서이 플러그인을 사용할 수 있습니다 : 그것은 당신이 무엇을 수정할 수 있기를 바랍니다 :)
// check if there is an backlink stored in actionStack, if yes than use it
if (($actionHistory = $this->getHelper('actionHistory'))) {
$request = $actionHistory->getBacklink();
if ($request) {
$actionHistory->popStack();
// use any of your redirect classes or simle redirector helper
// right path to previous site is accesible by $request->getUserParams()
$this->redirect($request->getUserParams());
}
}
그게 전부를 이 솔루션의 이론과 이점은 분명합니다.
나는 이해할 수 없다. 아무것도. 더 많은 정보를 제공해 주시겠습니까? – Carlos
더 좋습니까? – user1186173
링크 ('#')에서 해시를 사용할 수 있으며 실제 새로 고침은 곧바로 해시로 돌아갑니다. – aserwin