How To Use The Class AdminCоntrоller In Prestashop

How To Use The Class AdminCоntrоller In Prestashop

Today we will learn how to use the class AdminCоntrоller and will create our own model. Our Admin class will use its data. It all will be based on our new module Frequently Asked Questions. Let’s first describe the tables which our new module will use.

There will be 3 of them:

  • Belvg_faq
  • Belvg_lang
  • Belvg_shop

The fields of the table belvg_fаq:

  • Id_belvg_faq
  • Position
  • Active

The fields of the table belvg_lаng allow you to use class data in multi language stores.

  • Id_belvg_faq
  • Id_lang
  • Title
  • Content

The fields of the table belvg_shоp are responsible for multi-store support

  • Id_belvg_faq
  • Id_shop

As soon as the database fields have been defined we can create a class-model. Let’s call this class FAQ:

So, the model has been created. With its help the data will be stored\edited in the database tables. In order to work with data, to initiate processes of creating new FAQ blocks, to sort and view the list of already existing blocks we need a class inherited from AdminCоntrоller. So we create a class with the name AdminFAQ:

The method renderForm draws this form:

1

The array $this- >fields_list, which is responsible for the data displayed in the controller’s grid, is initialized in the constructor:

2

Download Frequently Asked Questions module.



10 comments

  1. jQuery

    jQuery is already available in the backoffice right after Prestashop installation.

  2. Hi,

    I’ve created my AdminBlockQuoteController.php and BlockQuote.php (class model).

    But when i click to edit a record in the fields_list. It loads the renderform, but not the data in the fields? The fields are blank.

    Could you possibly suggest what I might be doing wrong?

    Thanks!!

  3. Simon,

    It is pretty hard to say what exactly you are doing wrong without seeing the original version of your code. Perhaps, the problem is with the class of the model which interacts with your controller.

  4. Hi,

    I would like to do the same as you, but with 2 table.

    Is it possible ?

    I have a table for some elements, and another table with all names/descriptions etc

    Thanks

  5. Xavier,

    Yes, of course. That’s how most of the controllers work. For example, lets have a look at AdminCategoriesController.php witch works with _lang table as with the second table.

  6. Hi,

    The admin side controller is not showing order by, search fields and Bulk dropdown. Its simple listing only, Can you please advise.

    Thank You

Post a new comment

top