поскольку я знаю путь, на странице B я могу поместить Go Back , чтобы вернуться из B в A и т. д., и после этого я смогу вернуть страницу A, вернувшись из C в B и из A в A.Предположим, теперь вы хотите перейти на страницу B, начиная со страницы D. Очевидно, вы вернетесь на D, возвращаясь от C к B и от B к D, но на странице B кнопка «Назад» указывает на A. Итак, как, если вам нужна только кнопка для возврата на нужную страницу?
Я пробовал этот класс:
Код: Выделить всё
class ReturnHereVM
{
protected string $base='/';
protected string $backWardPage='';
protected string $forWardPage='';
protected string $curPage='';
protected string $curController='';
public function __construct(
?string $curController='',
){
$this->curController=$curController;
}
public function getBackWardPage()
{
return $this->backWardPage;
}
public function getCurPage(){
if(isset($_SESSION['returnHere']['curPage'])){
$this->curPage= $_SESSION['returnHere']['curPage'];
}
return $this->curPage;
}
public function getForWardPage()
{
return $this->forWardPage;
}
public function getCurController()
{
return $this->curController;
}
public function setCurController($val){
$this->curController=$val;
}
public function setBackWard($val){
$_SESSION['returnHere']['backWard'] = $val;
$this->backWardPage=$val;
}
public function setCurPage($val){
$_SESSION['returnHere']['curPage']=$val;
$this->curPage=$val;
}
public function setForWard($val)
{
$_SESSION['returnHere']['forWard'] = $val;
$this->forWardPage=$val;
}
public function setBacPages(){
}
public function setPages(string $start,string $val,string $fval){
if($start=='i'){
unset($_SESSION['returnHere']);
$this->setBackWard($this->base);
}else{
$this->setBackWard($start);
}
$this->setCurPage($val);
$this->setForWard($fval);
}
Я выполнил следующие шаги:
(
Код: Выделить всё
$this->contrNameКод: Выделить всё
$this->pagination на странице A
Код: Выделить всё
//because page A is the first, previous is Index = 'i'
$thisPage= '/' . $this->contrName . '/list/pag&' . $this->pagination->getPage();
$nextPage='/'.$this->contrName.'/detail/';//this is to reach page B
$this->returnHere->setPages('i',$thisPage,$nextPage);
Код: Выделить всё
$prevPage= $this->returnHere->getCurPage();
$thisPage= '/' . $this->contrName . '/detail/' . $id;
$nextPage= '/' . $this->contrName . '/edit/'.$id;//this is to reach page C
$this->returnHere->setPages($prevPage, $thisPage, $nextPage);
Код: Выделить всё
$prevPage = $this->returnHere->getCurPage();
$thisPage = '/' . $this->contrName . '/edit/' . $id;
$nextPage = '';//this is last page of the series
$this->returnHere->setPages($prevPage, $thisPage, $nextPage);
потому что это неправильный путь, я не пробовал со страницы D
Подробнее здесь: https://stackoverflow.com/questions/786 ... -using-php
Мобильная версия