SilverStripe PaginatedList抛出异常

时间:2015-08-20 13:37:43

标签: php pagination silverstripe

我正在使用3.1.13 SilverStripe CMS和Framework。在我的Page.php(类页面)中创建一个函数并在我的视图(page.ss)中初始化它后,我遇到了麻烦。 我想为我的项目创建一个分页。 以下是源和跟踪的错误:

[User Error] Uncaught Exception: The request must be readable as an array.
GET /?flushtoken=88455a3cc5497ee38dd7a61d75370221&flush=all

Line 28 in /var/www/project-name/framework/core/PaginatedList.php


Source

19   * Constructs a new paginated list instance around a list.
20   *
21   * @param SS_List $list The list to paginate. The getRange method will
22   *        be used to get the subset of objects to show.
23   * @param array|ArrayAccess Either a map of request parameters or
24   *        request object that the pagination offset is read from.
25   */
26  public function __construct(SS_List $list, $request = array()) {
27      if (!is_array($request) && !$request instanceof ArrayAccess) {
28          throw new Exception('The request must be readable as an array.');
29      }
30 
31      $this->request = $request;
32      parent::__construct($list);
33  }
34 


Trace

PaginatedList->__construct(DataList,)
HomePage.php:182
HomePage->PaginatedPages()
call_user_func_array(Array,Array)
Object.php:731
Object->__call(PaginatedPages,Array)
ViewableData.php:361
HomePage_Controller->PaginatedPages()
ViewableData.php:361
ViewableData->obj(PaginatedPages,,1,,)
SSViewer.php:91
SSViewer_Scope->getObj(PaginatedPages,,1,,)
SSViewer.php:504
SSViewer_DataPresenter->getObj(PaginatedPages,,1,,)
SSViewer.php:111
SSViewer_Scope->obj(PaginatedPages,,1)
.cache.themes.project-name.templates.Layout.HomePage.ss:400
include(/tmp/silverstripe-cache-php5.5.9-1ubuntu4.11-var-www-project-name/www-data/.cache.themes.project-name.templates.Layout.HomePage.ss)
SSViewer.php:1031
SSViewer->includeGeneratedTemplate(/tmp/silverstripe-cache-php5.5.9-1ubuntu4.11-var-www-project-name/www-data/.cache.themes.project-name.templates.Layout.HomePage.ss,HomePage_Controller,,Array,)
SSViewer.php:1098
SSViewer->process(HomePage_Controller,)
SSViewer.php:1094
SSViewer->process(HomePage_Controller)
Controller.php:203
Controller->handleAction(SS_HTTPRequest,index)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:198
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:78
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
RootURLController.php:130
RootURLController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:370
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:153
Director::direct(/,DataModel)
main.php:177

问题出在哪里?我正在关注this指令,当我在视图中调用我的函数时它会失败。

1 个答案:

答案 0 :(得分:2)

没关系!我刚刚意识到如果我想让$this->request工作,我需要将该函数放入class Page控制器。