我已经创建了一个模块,我想在admin选项卡(左)中看到他。但是,当单击链接时,我想重定向到模块的配置。
这里有很多图片可以帮助您理解。
我的管理员标签
当我单击链接我的页面时
但是我要转到我的配置模块
我已经创建了AdminYoutubeHomeController
在这种情况下,我如何重定向到我的模块?我搜索但什么也没发现...
多谢
答案 0 :(得分:0)
将您的管理控制器重定向到模块配置:
class AdminYourModuleController extends ModuleAdminController
{
public function __construct()
{
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminModules').'&configure=yourmodule');
}
}
然后在模块主类中显示带有功能getContent()
的模块配置。
答案 1 :(得分:0)
从presta 1.7开始,定义了一个属性选项卡,用于在模块中的“管理后台”菜单中添加“添加”选项卡。 >
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="javaheri.ghazaleh@gmail.com";
$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;
}
}
答案 2 :(得分:-1)
查找以下链接以在模块https://webkul.com/blog/create-modules-admin-controllers-without-creating-tab-prestashop/
上创建adminCOntroller在Prestashop中,大多数情况下,在创建模块时,我们需要创建管理控制器。在该模块中,要使管理控制器正常工作,我们必须在_DB_PREFIX _。’tab
”表中创建该管理控制器类的条目。通常,我们在模块安装时进行所有这些输入。
因此,如果要在模块中创建管理控制器,则可以用两种情况创建它–
您要为管理控制器创建一个标签。 您想要创建管理控制器而不为其创建选项卡。
例如,您想要一个在单击链接时打开的控制器,并且可能还有许多其他情况。
让我们通过示例了解这两种情况的过程-
让我们创建了一个名为inatallTab()的函数,该函数在模块的管理控制器的“标签”表中进行输入。
// 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:带有标签的管理控制器
/*
* 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 license@prestashop.com 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 <contact@prestashop.com>
* @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.
}
让我们看看如何通过以下屏幕截图在后台创建“孩子”或“父母”标签。
CASE-2:管理控制器,无需创建标签页
如果要创建管理控制器而不在模块中创建选项卡,则必须对上面的代码稍作更改,以在_DB_PREFIX _。'tab'表中创建管理控制器的条目。
我们只需要为代码中的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 license@prestashop.com 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 <contact@prestashop.com>
* @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_.tab页中的id_parent的值设置为-1。它将不会为您的管理员创建任何标签,并且您的管理员将正常工作。
完成上述过程后,您只需要在模块中创建管理控制器的类,并从管理控制器中编写所需功能的代码即可。
致谢