Prestashop:如何在HelperList中筛选

Prestashop:如何在HelperList中筛选

问题描述:

您好,我尝试筛选Backoffice中的列表。它显示过滤器,它也在点击搜索后保存,但没有任何事情发生。与分页一样。Prestashop:如何在HelperList中筛选

$schueler = $this->getAllSchuelerbyDiplom($id_diplom); 
    $diplom_name = $this->getDiplomNamebyID($id_diplom); 

    $fields_list = array(
     'id_schueler' => array(
      'title' => 'ID', 
      'align' => 'center', 
      'class' => 'fixed-width-xs', 
      'search' => true), 

     'customer_name' => array(
      'title' => $this->l('ID Customer')), 

     'id_gruppe' => array(
      'title' => $this->l('ID Gruppe')), 

     'name' => array(
      'title' => $this->l('Name'), 
      'filter_key' => 'name'.$diplom_name), 

     'vorname' => array(
      'title' => $this->l('Vorname')), 

     'punkte' => array(
      'title' => $this->l('Punkte')), 

     'bestanden' => array(
      'title' => $this->l('Bestanden'), 
      'active' => 'toggle', 
      'class' => 'fixed-width-xs', 
      'type' => 'bool'), 

     'date_added' => array(
      'title' => $this->l('Datum'), 
      'class' => 'fixed-width-xs', 
      'type' => 'date'), 
    ); 

    $helper = new HelperList(); 
    $helper->table = 'no-idea-what-this-is-for'; 
    $helper->title = $diplom_name; 
    $helper->shopLinkType = ''; 
    $helper->actions = array('view', 'edit', 'delete'); 
    $helper->listTotal = count($schueler); 
    $helper->identifier = 'id_schueler'; 
    $helper->token = Tools::getAdminTokenLite('AdminModules'); 
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name .'&diplom_name=' . $diplom_name; 

    return $helper->generateList($schueler, $fields_list); 

什么是错我的代码?什么是$ helper-> table用于?我尝试不同的东西有,但没有什么帮助......

编辑

public function getAllSchuelerbyDiplom($id_diplom) { 
    $query = new DbQuery(); 
    $query->select('s.*, CONCAT(c.firstname,\' \',c.lastname) AS customer_name'); 
    $query->from($this->table_name.'_schueler', 's'); 
    $query->leftJoin('customer', 'c', 's.id_customer = c.id_customer'); 
    $query->where('s.id_diplom = ' . (int)$id_diplom); 
    return Db::getInstance()->ExecuteS($query); 
} 

的问题是,在使用HelperList对象本身将只显示过滤器,但不会过滤的实际数据列表中找到您。

在您的$this->getAllSchuelerbyDiplom($id_diplom);方法中,我假定您执行SQL查询来检索所有行,但是您需要修改它以说明任何过滤器,分页(每页的页码和行)或排序。您必须检查Cookie中设置的GET/POST值或值以检测它们。

$helper->table设置表名称和列表操作的前缀名称,以便它们与页面上可能具有的任何其他列表不同。

编辑:

设置分页和页面的实例

public function getPage() 
{ 
    // $tableName must be equal to what you set in $helper->table 

    // Check if page number was selected and return it 
    if (Tools::getIsset('submitFilter'.$tableName)) { 
     return (int)Tools::getValue('submitFilter'.$tableName); 
    } 
    else { 
     // Check if last selected page is stored in cookie and return it 
     if (isset($this->context->cookie->{'submitFilter'.$tableName})) { 
      return (int)$this->context->cookie->{'submitFilter'.$tableName}; 
     } 
     else { 
      // Page was not set so we return 1 
      return 1; 
     } 
    } 
} 

public function getRowsPerPage() 
{ 
    // $tableName must be equal to what you set in $helper->table 

    // Check if number of rows was selected and return it 
    if (Tools::getIsset($tableName. '_pagination')) { 
     return (int)Tools::getValue($tableName. '_pagination'); 
    } 
    else { 
     // Check if number of rows is stored in cookie and return it 
     if (isset($this->context->cookie->{$tableName. '_pagination'})) { 
      return (int)$this->context->cookie->{$tableName. '_pagination'}; 
     } 
     else { 
      // Return 20 rows per page as default 
      return 20; 
     } 
    } 
} 

public function getAllSchuelerbyDiplom($id_diplom) { 
    $query = new DbQuery(); 
    $query->select('s.*, CONCAT(c.firstname,\' \',c.lastname) AS customer_name'); 
    $query->from($this->table_name.'_schueler', 's'); 
    $query->leftJoin('customer', 'c', 's.id_customer = c.id_customer'); 
    $query->where('s.id_diplom = ' . (int)$id_diplom); 

    // Limit the result based on page number and rows per page 
    $query->limit($this->getRowsPerPage(), ($this->getPage() - 1) * $this->getRowsPerPage()); 

    return Db::getInstance()->ExecuteS($query); 
} 

你可以把一个p(Tools::getAllValues()); d($this->context->cookie->getAll();您生成后,然后列表中的列表中设置一个过滤器,它会告诉你所有的变量您需要创建过滤器和订购。

+0

是的我有正常的ExecuteS功能...你能解释一个例子如何在我的函数中使用GET/Post? 我编辑了我原来的帖子。我在那里展示了我的功能。非常感谢! –

+0

@EmanuelSchiendorfer我添加了一个例子。 – TheDrot

+0

谢谢!你的例子帮助我做了很多分页工作!只需要改变一些小事。我认为在你的代码中有两次“;”失踪。 –