Jump to content

how to create new admin page in prestshop 1.6.x


samuelprabhu

Recommended Posts

Hi!

 

  How to create new admin page in prestashop 1.6.x.

 

    I have followed the below steps in previous occasion:

 

 

 

create controllers/admin/AdminPageController.php with the follwing content:

class AdminPageController extends AdminController
{
public function initContent()
{
parent::initContent();
$smarty = $this->context->smarty;

$smarty->assign('test', 'test1');

}
}

Delete: /cache/class_index.php

Create: admin\themes\default\template\controllers\page\content.tpl

zzz{$test}zzz

At BackOffice -> Administration -> Menus -> [Add New]:

Name: Page
Class: AdminPage
Parent: Catalog

Click the [save] button and the menu item should appear at the "Catalog" menu.

The above steps worked well in prestashop 1.5.x versions.

I tried the same in pretashop 1.6.x, but it is showing blank even after explicitly write the html content in tpl file or give the assigned smartry variable 'test'.

My questions are,

1) how to call the custom tpl file in custom admin controller to show tpl content in prestashop 1.6.x?

2) how to send values to tpl file from custom admin controller in prestashop 1.6.x?

3) how to assign the tpl file to a php variable?

I need to create custom controller and custom tpl in admin and need to show in admin.

Anyone please help me to sort out this with sample code.

 

 

 

 

Link to comment
Share on other sites

Thx jgamio.

 

I have another question regarding the module. Where are the tabs shown ? Because after i installed the module i was hopping that i will see in the left a menu with a sub element ... but they are not there ... I`m missing something ?

 

Regards

Link to comment
Share on other sites

The sample put the menu on the main menu at bottom with aditional menu look the install function, i dont know why didnt work for you but look close

 

 

1) Jus create the tab object
$parent_tab = new Tab();
 
2) Just put the name in the actual language
$parent_tab->name[$this->context->language->id] = $this->l('Main Tab Example');
 
3) Set the class name Your controller 
$parent_tab->class_name = 'AdminMainExample';
 
4) Set the parent code  You can see defaults codes on your database look for ps_tabs, if you need create a generic these is not the best you should find the paren from database to create the parent
$parent_tab->id_parent = 0; // Home tab
 
5) Set the module from the menu 
$parent_tab->module = $this->name;
 
6) Add the tab to the database
$parent_tab->add();
 
7) you have a position to set the position on the list
  • Like 2
Link to comment
Share on other sites

 

The sample put the menu on the main menu at bottom with aditional menu look the install function, i dont know why didnt work for you but look close

 

 

1) Jus create the tab object
$parent_tab = new Tab();
 
2) Just put the name in the actual language
$parent_tab->name[$this->context->language->id] = $this->l('Main Tab Example');
 
3) Set the class name Your controller 
$parent_tab->class_name = 'AdminMainExample';
 
4) Set the parent code  You can see defaults codes on your database look for ps_tabs, if you need create a generic these is not the best you should find the paren from database to create the parent
$parent_tab->id_parent = 0; // Home tab
 
5) Set the module from the menu 
$parent_tab->module = $this->name;
 
6) Add the tab to the database
$parent_tab->add();
 
7) you have a position to set the position on the list

 

 

Hi jgamio,

 

Thank you for helping me out.

 

At second point i`ve used a loop to set the tab for all the languages installed :

foreach (Language::getLanguages(true) as $lang) {
    $tab->name[$lang['id_lang']] = $this->l('Name displayed on the tab');
} 

at 3 ... for the main tab i`ve set the parent = 0 and for the child one i`ve set the parent tab id as in the module canvas

 

Another thing that i don`t not understand is the $tab->class_name. In the canvas module for the parent it sets this property to AdminMainExample (and here i have a problem because i can not find this class in the canvas module package).

 

The rest is clear for me, but when i install the module if i check the ps_tab table i can not find my new tabs in there :| and i receive no error message.

 

Regards,

Cristian Nicolae Nicorici

Link to comment
Share on other sites

// Install Tabs
$parent_tab = new Tab();
// Need a foreach for the language
$parent_tab->name[$this->context->language->id] = $this->l('Main Tab Example');
$parent_tab->class_name = 'AdminMainExample';
$parent_tab->id_parent = 0; // Home tab
$parent_tab->module = $this->name;
$parent_tab->add();

$tab = new Tab();
// Need a foreach for the language
$tab->name[$this->context->language->id] = $this->l('Tab Example');
$tab->class_name = 'AdminExample';
$tab->id_parent = $parent_tab->id;
$tab->module = $this->name;
$tab->add();

Sorry this is from the module canvas. I forgot to include it in the prev post.

 

Regards,

Cristian Nicolae Nicorici

Link to comment
Share on other sites

Hi

 

I think they put on the parent a generic name class no a real one   because these only is used to show the item Iink the menu

 

I dont know why didnt install I use these for my own modules it works 

 

Are you sure is no data on ps_tabs

Link to comment
Share on other sites

 

The sample put the menu on the main menu at bottom with aditional menu look the install function, i dont know why didnt work for you but look close

 

 

1) Jus create the tab object
$parent_tab = new Tab();
 
2) Just put the name in the actual language
$parent_tab->name[$this->context->language->id] = $this->l('Main Tab Example');
 
3) Set the class name Your controller 
$parent_tab->class_name = 'AdminMainExample';
 
4) Set the parent code  You can see defaults codes on your database look for ps_tabs, if you need create a generic these is not the best you should find the paren from database to create the parent
$parent_tab->id_parent = 0; // Home tab
 
5) Set the module from the menu 
$parent_tab->module = $this->name;
 
6) Add the tab to the database
$parent_tab->add();
 
7) you have a position to set the position on the list

 

 

Hi! Jgamio,

 

    Thanks for your answer.

   I have created the admin page as mentioned in the link you provided.

 

I still have some doubts in that  admin example controller,

1) I need to edit the query that displays the list ?

2) How to get and insert values from form created with helper class as in the example?

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

HI,

 

You should look the code got to

 

/controllers/admin

 

check out how they work take a simple one like AdminStatesController

 

you can see there how put some relations and how insert and edit new data

Link to comment
Share on other sites

HI,

 

You should look the code got to

 

/controllers/admin

 

check out how they work take a simple one like AdminStatesController

 

you can see there how put some relations and how insert and edit new data

 

Thanks a lot.. Job done...

One question is there any way to find the difference between add and edit in postProcess() method.

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...