Jump to content

How to display a form in front office using a module front controller?


JoelWebsites

Recommended Posts

Below is the code I have tried to create in my test module

 

I am getting Fatal errors Fatal error: Call to undefined method testmoduledisplayModuleFrontController::addRowAction() in 

testmoduledisplayModuleFrontController::l() in 

 

and similar errors ..

 

How do I solve them ? thank you..

<?php

class testmoduledisplayModuleFrontController extends ModuleFrontController

{

  public function initContent()

  {

    parent::initContent();

    $this->setTemplate('display.tpl');

$this->renderForm();

  }

  public function __construct()

{

    $this->context = Context::getContext();

    $this->table = 'games';

    $this->className = 'Games';

    $this->lang = true;

    $this->addRowAction('edit');

    $this->addRowAction('delete');

    $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'),

    'confirm' => $this->l('Delete selected items?')));

    $this->multishop_context = Shop::CONTEXT_ALL;

 

    $this->fieldImageSettings = array(

        'name' => 'image',

        'dir' => 'games'

    );

 

    $this->fields_list = array(

        'id_game' => array(

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

            'width' => 25

        )

    );

 

    $this->identifier = 'id_game';

    parent::__construct();

}

 

public function renderForm()

{

    if (!($obj = $this->loadObject(true)))

        return;

 

    $games_list = Activity::getGamesList();     

 

    $this->fields_form = array(

        'tinymce' => true,          

        'legend' => array(

            'title' => $this->l('Game'),

            'image' => '../img/admin/tab-payment.gif'

        ),

        'input' => array(

            array(

                  'type' => 'select',

                  'label' => $this->l('Game:'),

                  'desc' => $this->l('Choose a Game'),

                  'name' => 'id_games',

                  'required' => true,

                  'options' => array(

                        'query' => $games_list,

                        'id' => 'id_game',

                        'name' => 'name'

                    )

            ),

            array(

                'type' => 'text',

                'label' => $this->l('Game Title:'),

                'name' => 'name',

                'size' => 64,

                'required' => true,

                'lang' => true,

                'hint' => $this->l('Invalid characters:').' <>;=#{}'

            ),

            array(

                'type' => 'file',

                'label' => $this->l('Photo:'),

                'name' => 'uploadedfile',

                'id' => 'uploadedfile',

                'display_image' => false,

                'required' => false,

                'desc' => $this->l('Upload your document')

            )

        )

    );

 

    $this->fields_form['submit'] = array(

        'title' => $this->l('   Save   '),

        'class' => 'button'

    );

 

    return parent::renderForm();

}  

}

Link to comment
Share on other sites

  • 10 months later...
  • 11 months later...
  • 1 year later...

JoelWebSites

You can't create a form with the Helper in the Front Controller like in the Admin Controller.

You have to do it the old way, with the template and everything.

If you check the ModuleFrontController class and the FrontController class, you can see that their construct is very different from yours.

 

The Helper is only for BackOffice

And in the FrontController, you can do a function like this :

protected function l($string)
    {
        return Translate::getModuleTranslation('name_module', $string, 'name_front_controller');

    }

 

And then $this->l()

All the errors you get is because all the functions and properties you are calling don't exist in the FrontController, only in the AdminController.

 

But maybe in future versions of Prestashop it will be possible with the integration of Symfony

Edited by Steeve (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...