ChewieTheWookie Posted February 4, 2018 Share Posted February 4, 2018 (edited) Hi there fellow developers, I need a bit of help with regard to the actions performed on a list generated by HelperList. The documentation only specifies that having the buttons (edit, delete, view) doesn't do anything but you have to "add proper code for the buttons", but there's no clear example on how to do that, what to add to the controller, and what function is actually called when you click on the buttons. So here's a child admin controller for a module, with a list generated, that part works fine. When you move the mouse over to edit, view, or delete, it's obvious the helper generates links like "update[tablename]", "delete[tablename]", and "view[tablename]", but there's no way you can actually call any function from the same controller. I tried creating public functions update, delete, view, to no avail. How are we supposed to tell the controller or the helper, what function to be called on clicking those buttons ? Here's the function for displaying the list (works perfectly) $db = Db::getInstance(); $sql='SELECT * FROM ' . _DB_PREFIX_ . 'bcard'; $results=$db->ExecuteS($sql); $this->fields_list = array( 'bcard_id' => array( 'title' => $this->l('Id'), 'width' => 140, 'type' => 'text' ), 'bcard_size' => array( 'title' => $this->l('Size'), 'width' => 140, 'type' => 'text' ), 'bcard_description' => array( 'title' => $this->l('Description'), 'width' => 'auto', 'type' => 'text' ) ); $helper= new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; $helper->listTotal = count($results); $helper->actions = array('edit', 'delete', 'view','test'); $helper->module = $this; $helper->identifier = 'bcard_id'; $helper->show_toolbar = false; $helper->title = 'List of printable models'; $helper->table = 'bcard'; $helper->token = Tools::getAdminTokenLite('AdminBcardprint'); $helper->currentIndex = AdminController::$currentIndex; return $helper->generateList($results,$this->fields_list); } And here's an example of the link you get on the "Edit" button /[adminfolder]index.php?controller=AdminBcardprint&bcard_id=1&updatebcard&token=..... So where do I construct/build that "update" function ? Is it part of another helper ? Does a parent/core function from somewhere get called ? I've just seen that mr. Xavier Borderie actually admitted in a post, that for version 1.7 a lot of the functionality is still under the hood, and not publicly available, so I'm guessing someone else had to have had this issue too. Can anyone please tell me how can I build those functions for CRUD operations on that list, using either helpers, or custom functions ? Thank you ! Edited February 7, 2018 by ChewieTheWookie (see edit history) Link to comment Share on other sites More sharing options...
Pierre_d Posted February 6, 2018 Share Posted February 6, 2018 Hi, it's just a bit more complicated. I can't provide you with a step-by-step tutorial on how to do this, but you need to follow PS MVC guidelines. You need to create your own controller extending ModuleAdminController and you need to create a class to model your entity. I found a detailed tutorial about this in Fabien Seny's book, "Développez vos propres modules PS". It's not expensive but it's in French. You may find something similar with Google. Link to comment Share on other sites More sharing options...
ChewieTheWookie Posted February 7, 2018 Author Share Posted February 7, 2018 On 2/6/2018 at 9:35 AM, Pierre_d said: ..Fabien Seny's book, "Développez vos propres modules PS". It's not expensive but it's in French. You may find something similar with Google. Thank you, I will look it up, I do understand French, too at base level. In the meantime, I've done just that, written a specific child controller extending ModuleAdminController, and I've found some good videos online on youtube, detailing the process, however, I feel very sad that the documentation is not only incorrect, but incomplete, and ... well, it's not actually useful most of the times. Thank you for your response. We'll rely on each-other I guess, if we can't rely on official step-by-step docs. Right now I'm baffled by how poorly the list pagination is done, too, I'll have to hide the header of the list and compose the screen with parts written for header, (add new, filter/search, reset), body part (the list with the edit/delete buttons), and then the footer for the pagination part. Link to comment Share on other sites More sharing options...
Pierre_d Posted February 8, 2018 Share Posted February 8, 2018 I agree, the official documentation is just an introduction, not a detailed reference manual. I guess it's a deliberate choice from PS team to invest time first on development. Creating good, comprehensive documentation takes time, a lot of time... Regarding the pagination, your database query needs to take this into account by making use of the LIMIT keyword. If you create a class for bcard, extending ObjectModel and if you follow PS guidelines, ObjectModel will retrieve the data from the database and pagination should work, as well as insert, update, delete... Link to comment Share on other sites More sharing options...
sfweb Posted July 12, 2018 Share Posted July 12, 2018 Hi ChewieTheWookie, I have the same problem, could you tell me please how did you make it work? I'm trying to do with HelperList inside the renderForm function in the controller, but it seems something is wrong with my code. What I want is open a detail page clicking on view or edit in the module list (see image attached). Link to comment Share on other sites More sharing options...
sfweb Posted July 12, 2018 Share Posted July 12, 2018 After I wrote the post I've just found a solution, here is my code: This the renderForm inside my controller: public function renderForm() { $fields_list = array( 'id_test' => array( 'title' => $this->l('Col1'), 'width' => 25 ), 'field1' => array( 'title' => $this->l('Col2'), 'width' => 25 ), 'field2' => array( 'title' => $this->l('Col3'), 'width' => 25 ), ); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; $helper->identifier = 'id_test'; $helper->show_toolbar = true; $helper->title = 'Boomprice Used'; $helper->table = 'boomprice_used_cod'; $database_data=''; $sql = 'SELECT * FROM '._DB_PREFIX_.'table_name'; $results = Db::getInstance()->ExecuteS($sql); if (empty($results)) { $database_data= 'Nothing'; } else { $database_data = $results; } return $helper->generateList($database_data, $fields_list); } I hope this code will help someone. 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