Koko888 Posted August 30, 2014 Share Posted August 30, 2014 Hello, I have a Helperlist rendered, and for each clickable row I would like to have a redirection to an external page, or do this by clicking on the 'view' action. The next code displays a sample list, how can I go to the external link after clicking to one of the table elements. Thanks in advance public function MyList() { $content = array( array( 'id' => 1, 'SKU' => 153, 'Name' => 'Test1', ), array( 'id' => 2, 'SKU' => 154, 'Name' => 'Test2', ), array( 'id' => 3, 'SKU' => 155, 'Name' => 'Test3', ), ); $fields_list = array( 'id' => array( 'title' => 'ID', 'align' => 'center', 'class' => 'fixed-width-xs', ), 'SKU' => array( 'title' => 'SKU', 'align' => 'center', 'class' => 'fixed-width-md', ), 'Name' => array( 'title' => 'Name', 'align' => 'center', 'class' => 'fixed-width-md', ), ); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->actions = array(); $helper->show_toolbar = false; $helper->module = $this; $helper->listTotal = count($content); $helper->identifier = 'List Test'; $helper->title = 'List '; $helper->actions = array('view'); $helper->table = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; return $helper->generateList($content, $fields_list); } Link to comment Share on other sites More sharing options...
Enrique Gómez Posted August 31, 2014 Share Posted August 31, 2014 (edited) you can override the view action (once you have added in the controller via $this->addRowAction('view') ) public function displayViewLink($token = null, $id, $name = null) Or you can add a specific row action like $this->addRowAction('preview'); and create the function public function displayPreviewLink($token = null, $id, $name = null) { $dmEquip=new DmEquipacion($id); $url=_PS_BASE_URL_.__PS_BASE_URI__."equipaciones/".$dmEquip->url_amigable; $html='<a href="'.$url.'" title="Ver Equipación" target="_blank"> <img src="../img/admin/details.gif" alt="Ver Equipación" /> </a>'; return $html; } so you can generate the html for each row (having the $token and $id of the row) Edited August 31, 2014 by Enrique Gómez (see edit history) 1 Link to comment Share on other sites More sharing options...
Koko888 Posted August 31, 2014 Author Share Posted August 31, 2014 Hello Enrique, thank you for your answer, it was really helpful. I already did what you suggested, but I'm having problems to get the $id, I think it is because I'm filling the list with my own content not from a DB table, any idea of how can i get the id of my table content? Thanks in advance, Jorge Link to comment Share on other sites More sharing options...
Enrique Gómez Posted August 31, 2014 Share Posted August 31, 2014 If you have a look for example at the native module blockwishlist or blockreinsurance you will see that the generateList return $html.$helper->generateList($this->getListContent((int)Configuration::get('PS_LANG_DEFAULT')), $this->fields_list); needs a source like this select which returns an array of rows protected function getListContent($id_lang) { return Db::getInstance()->executeS(' SELECT r.`id_reinsurance`, r.`id_shop`, r.`file_name`, rl.`text` FROM `'._DB_PREFIX_.'reinsurance` r LEFT JOIN `'._DB_PREFIX_.'reinsurance_lang` rl ON (r.`id_reinsurance` = rl.`id_reinsurance`) WHERE `id_lang` = '.(int)$id_lang.' '.Shop::addSqlRestrictionOnLang()); } the fields are $this->fields_list = array( 'id_reinsurance' => array( 'title' => $this->l('Id'), 'width' => 120, 'type' => 'text', ), 'text' => array( 'title' => $this->l('Text'), 'width' => 140, 'type' => 'text', 'filter_key' => 'a!lastname' ), ); if (Shop::isFeatureActive()) $this->fields_list['id_shop'] = array('title' => $this->l('ID Shop'), 'align' => 'center', 'width' => 25, 'type' => 'int'); for the Helper defined as $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; $helper->identifier = 'id_reinsurance'; $helper->actions = array('edit', 'delete'); $helper->show_toolbar = true; $helper->imageType = 'jpg'; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Add new') ); $helper->title = $this->displayName; $helper->table = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; Take into account that the identifier must be in the rows passed to generateList. In this case id_reinsurance 1 Link to comment Share on other sites More sharing options...
Koko888 Posted September 1, 2014 Author Share Posted September 1, 2014 Hi Enrique, thank you very much, I could solve my issue by using the $helper->identifier as you mentioned it in your last reply. Regards, Jorge Link to comment Share on other sites More sharing options...
Enrique Gómez Posted September 2, 2014 Share Posted September 2, 2014 Perfect. Please change the title and add a [solved] prefix, to mark this post as solved. And if you like my answer it would be great that you press the like button . 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now