Search code examples
phpmoduleprestashopprestashop-1.6

Using renderView() in a custom ModuleAdminController (PS1.6)


I am trying to add the view action to my back office module page but i cannot display anything with the renderview() function. I can already display my list with renderList() and it's working well. I also tried renderForm() and it works well too but it seemz i can't get renderView() to display something.

public function renderView(){

    if(!($config = $this->loadObject())){
        return;
    }

    $data = Config::getDataForm(Tools::getValue('id_config'));
    // var_dump($data);

    $this->tpl_view_vars = array(
        'id_config' => $data['id_config'],
        'prix' => $data['prix'],
        'hauteur' => $data['hauteur_passage']
        );

    return parent::renderView();

}

This is a pretty basic code. My getDataForm($id_config) is getting fields from database in an array so that i can display it. I can see the var_dump displaying for a short time before displaying the blank page with prestashop header and footer. I tried to see if i was doing something wrond by checking other AdminController such as AdminCartsController or AdminCustomersController but it seems that their renderView() function is more or less written the same way.

Thanks in advance for your help !


Solution

  • I manage to resolve this problem simply by adding a view tpl in /modules/mymodule/views/templates/admin/mymodule/helpers/view/.

    I wrongly assumed that it didn't need to create a template file for the view action as it didn't need one for the list and form action. After searching through modules and admin files i managed to find that there were indeed a custom view.tpl for the view action.

    The renderview() method lets you set up the variables you want to use in your view.tpl.

    For more information on how it works, you can check AdminCustomersController to see how it is on the controller side and /adminxxxx/themes/default/template/controllers/customers/helpers/view/view.tpl to see how the template is written.

    Feel free to edit or comment if you need more information