Custom Prestashop Admin Module

13,539

If it is an admin module only, then you will have no need to create any views. Because Prestashop provides a nice structure for admin section which is easy to use and we dont need to use any views or .tpl files. For admin section, normally three types of views or .tpl files are required, one for data display in grid, second for form and third for displaying a single record.

Prestashop already created .tpl files for them which you can find in "admin_folder/themes/default/templates". In our controllers for admin, for form and for data grid, we just create arrays and PS handles to view the form and data grid according to the arrays we created.

So if you need a custom form at admin, then create a public function renderForm and create the form array in it, like below:

$this->fields_form = array(
        'legend' => array(
            'title' => $this->l('Video'),
            'image' => '../img/admin/tab-genders.gif'
        ),
        'input' => array(
            array(
                'type' => 'text',
                'label' => $this->l('Video Title:'),
                'name' => 'title',
                'lang' => true,
                'size' => 70,
                'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:',
                'required' => true
            ),

            array(
                'type' => 'textarea',
                'label' => $this->l('Video Code'),
                'name' => 'video_code',
                'rows' => 5,
                'cols' => 70,
                'desc' => $this->l('Place the embed code for the video')
            ),

        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'button'
        )
    );

    return parent::renderForm();

} /* End of render member */

For other fields, checkout other prestashop admin controllers and you will see that how easily we can create forms in PS using that simple definitions in the arrays and we dont need to create .tpl files.

For front end, we can use the new modules MVC structure, where our module folder have sub folders for controllers (controllers/front, controllers/admin) , views and models .

Hope this will help you.

Thank you

Share:
13,539
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am developing a module for prestashop (basically, it's a very custom import of data and the only thing I need is to have a form and process data). I have created controller class derived from the ModuleAdminController but the problem is where should I put the tpl file containing the look of my custom form?

    I realize that I can put tpl file to the templates but I want to keep all files within my module folder, is it possible (probably somewhere like "/views/templates/admin")?