Silversstripe:我的页面上有一个博客,有多个页面,每页有10个条目。我想让我的控制器知道当前正在查看博客的哪个页面。
我有以下代码:
public function dependsOnPage() {
$page = getPageHere; /*How can I get which page of the blog I'm currently on?*/
$i = ($page*10)-10;
echo $i;
}
第二页上的URL看起来像这样,例如:?起始=10第三个像这样?启动=20
有人知道我怎么能在银条球场做到这一点吗?
我试过了:
//echo SiteTree::get_by_link('news')->Link();
//echo (Director::urlParam());
//echo Director::getCurentPage();
echo Director::get_current_page();
echo Director::baseURL();
$test = $_GET['url'];
echo $test;
echo $this->request->param('ID');
// echo Director::absoluteURL('', false);
//echo $this->getCurentPage();
//echo $this->request->param() ;
//echo $this->URLSegment;
//echo Director::absoluteBaseURL();
//echo $this->param();
//echo $this->getURLParams();
//echo SS_HTTPRequest->param();
解决方案:
$urlParam=控制器::curr()->getRequest()->getVar('start');
我们可以在SS_HTTPRequest
对象上用一些函数检索Post和Get变量。我们可以从Controller
中获得SS_HTTPRequest
对象。
SS_HTTPRequest
具有检索Get变量的函数getVar($variableName)
。
如果您的函数在控制器中,您可以调用以下命令来获取$_GET
变量:
$startValue = $this->getRequest()->getVar('start');
如果函数在对象类中,则在获得$_GET
变量之前,首先需要获得页面控制器:
$startValue = Controller::curr()->getRequest()->getVar('start');