Reputation: 103
I have create a module, and i want to see him in the admintab (in left). But when a click on the link, i want to be redirect to the configuration of the module.
Here many picture to help you to understand.
My admintab
When i click on the link my page
But i want to go to my configuration module
I have create AdminYoutubeHomeController
How in this i can do redirect to my module ? I search but i found nothing...
Thanks by advance
Upvotes: 1
Views: 2969
Reputation: 2117
from presta 1.7 a property tabs is defined for add tab to admin backoffice menu in your module define this public property and add a file in yourmoduledirectory/controllers/admin/{class_name}Controller.php that extends ModuleAdminController e.g:
class AdminPLevelController extends ModuleAdminController
{
public function renderView()
{
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}
}
and my module file is like this,(my module name is plevel
)
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class Plevel extends Module
{
public $tabs = array(
array(
'name' => 'Price Level', // One name for all langs
'class_name' => 'AdminPLevel',/**this is class_name defined in above code*/
'visible' => true,
'parent_class_name' => 'ShopParameters',
));
public function __construct()
{
$this->name="plevel";
$this->tab="dashboard";
$this->version="1.0.0";
$this->author="[email protected]";
$this->need_instance=0;
$this->ps_versions_compliancy=array('min'=>'1.6','max'=>_PS_VERSION_);
$this->bootstrap=true;
$this->context=Context::getContext();
$this->displayName=$this->l("plevel");
$this->description=$this->l("change order print page");
$this->confirmUninstall=$this->l('Are you sure you want to uninstall');
parent::__construct();
}
public function install()
{
if (!parent::install())
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
}
Upvotes: 1
Reputation: 1022
Redirect your admin controller to module configuration:
class AdminYourModuleController extends ModuleAdminController
{
public function __construct()
{
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminModules').'&configure=yourmodule');
}
}
And then display module configuration with function getContent()
in your module main class.
Upvotes: 3
Reputation: 1273
Look this link for create adminCOntroller on the module : https://webkul.com/blog/create-modules-admin-controllers-without-creating-tab-prestashop/
In Prestashop while creating a module mostly we need to create Admin Controllers. In the module, to make an admin controller work we must create an entry of that admin controller’s class in _DB_PREFIX_.’tab
’ table. And generally, we make all these entries at the time of module installation.
So if you are creating your admin controllers in your module you can create it with two cases –
You want to create a tab for your admin controller. You want to create your admin controller without creating a tab for it.
For example your want a controller which opens on click of a link and many other cases may be there.
Lets understand the process of both case with examples-
Lets we have created a function with name inatallTab() which makes entries in the ‘tab’ table for our module’s admin controllers.
// Lets you want to create a child tab under 'Shipping' Tab. As we know Shipping Tab's class name is 'AdminParentShipping'
$this->installTab('AdminMyControllerName', 'My Tab Name', 'AdminParentShipping');
// Lets you want to create a parent tab. Then call the installTab() like below example-
$this->installTab('AdminMyControllerName', 'My Parent Tab Name');
CASE-1 : Admin Controller with Tab
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
public function installTab($yourControllerClassName, $yourTabName, $tabParentControllerName = false)
{
$tab = new Tab();
$tab->active = 1;
$tab->class_name = $yourControllerClassName;
// e.g. $yourControllerClassName = 'AdminMyControllerName'
// Here $yourControllerClassName is the name of your controller's Class
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = $yourTabName;
// e.g. $yourTabName = 'My Tab Name'
// Here $yourTabName is the name of your Tab
}
if ($tab_parent_controller_name) {
$tab->id_parent = (int) Tab::getIdFromClassName($tabParentControllerName);
// e.g. $tabParentControllerName = 'AdminParentAdminControllerName'
// Here $tabParentControllerName is the name of the controller under which Admin Controller's tab you want to put your controller's Tab
} else {
// If you want to make your controller's Tab as parent Tab in this case send id_parent as 0
$tab->id_parent = 0;
}
// $this->name is the name of your module to which your admin controller belongs.
// As we generally create it in module's installation So you can get module's name by $this->name in module's main file
$tab->module = $this->name;
// e.g. $this->name = 'MyModuleName'
$tab->add();
// make an entry of your tab in the _DB_PREFIX_.'tab' table.
}
Let’s have a look how your Child or Parent tabs are created in your backoffice with the help of the below screenshot.
CASE-2 : Admin Controller without creating Tab
If you want to create your admin controller without creating a tab in your module then you have to make a slight change in the above code which create entries of the your admin controller in the _DB_PREFIX_.’tab’ table .
We just need to passs -1 for the field id_parent in the code. Lets have a look on the code for this case.
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
$tab = new Tab();
$tab->active = 1;
$tab->class_name = $class_name;
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = $tab_name;
}
//If you don't want to create a tab for your admin controller then Pass id_parent value as -1.
$tab->id_parent = -1;
$tab->module = $this->name;
return $tab->add();
So as you have seen if we set the value if id_parent in the _DB_PREFIX_.’tab’ table as -1 .It will not create any tab for your admin controller and your admin controller will work normally.
After the above process, you just need to create your admin controller’s class in your module and write code for the functions you need from your admin controller.
Regards
Upvotes: 0