我已经创建了一个模块,我想在admintab(左侧)中看到他。但是当点击链接时,我想重定向到模块的配置。
这里有很多图片可以帮助你理解。
我的admintab
当我点击链接我的页面
但我想转到我的配置模块
我创建了AdminYoutubeHomeController
我怎么能重定向到我的模块?我搜索但我一无所获......
谢谢你提前
将管理控制器重定向到模块配置:
class AdminYourModuleController extends ModuleAdminController
{
public function __construct()
{
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminModules').'&configure=yourmodule');
}
}
然后在模块主类中使用函数getContent()
显示模块配置。
从presta 1.7中,为模板中的admin backoffice菜单定义了一个属性选项卡,定义了这个公共属性,并在你的模块目录/ controllers / admin / {class_name}中添加了一个文件,扩展了ModuleAdminController,例如:
class AdminPLevelController extends ModuleAdminController
{
public function renderView()
{
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}
}
我的模块文件是这样的,(我的模块名称是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;
}
}
在模块上查看此链接以创建adminCOntroller:https://webkul.com/blog/create-modules-admin-controllers-without-creating-tab-prestashop/
在Prestashop创建模块时,我们需要创建管理控制器。在模块中,为了使管理控制器工作,我们必须在_DB_PREFIX _。'tab
'表中创建该管理控制器类的条目。通常,我们在模块安装时制作所有这些条目。
因此,如果您在模块中创建管理控制器,则可以使用两种情况创建它 -
您想为管理员控制器创建一个选项卡。您想要创建管理控制器而不为其创建选项卡。
例如,您需要一个通过点击链接打开的控制器,许多其他情况可能在那里。
让我们通过例子了解这两种情况的过程 -
让我们创建一个名为inatallTab()的函数,它在我们模块的管理控制器的'tab'表中创建条目。
// 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:带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.
}
让我们看一下如何借助以下屏幕截图在后台创建您的Child或Parent选项卡。
CASE-2:管理员控制器,无需创建Tab
如果要创建管理控制器而不在模块中创建选项卡,则必须在上面的代码中稍作更改,以便在_DB_PREFIX _。'选项卡'表中创建管理控制器的条目。
我们只需要为代码中的字段id parent传递-1。让我们来看看这个案例的代码。
/*
* 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();
因此,您已经看到我们是否将_DB_PREFIX _。'选项卡'表中的id_parent设置为-1。它不会为您的管理控制器创建任何选项卡,您的管理控制器将正常工作。
完成上述过程后,您只需在模块中创建管理控制器的类,并从管理控制器中编写所需功能的代码。
问候