我想知道如何在opencart中创建自定义管理面板页面。
需要使用 Controller 登录-管理面板似乎没有使用与普通站点相同的 Controller 。我知道how to make custom pages with opencart(但这不是给管理员的)
一个简单的Hello World示例将很棒
最佳答案
OpenCart 2.x
路径名称在OpenCart 2中已更改-您将要创建admin/controller/extension/module/hello.php admin/language/en-gb/extension/module/hello.php admin/view/template/extension/module/hello.tpl
然后路线变成admin/index.php?route=extension/module/hello
OpenCart 1.x
我发现了如何做到这一点。 OpenCart使用MVC模式。我建议阅读有关How to be an OpenCart Guru?的有关学习系统工作原理的文章-此Admin工作流也应足以满足客户需求。
1)在
admin/controller/custom/helloworld.php
中创建一个新文件您的文件名和 Controller 名称应按desc顺序相同:
helloworld.php
<?
class ControllerCustomHelloWorld extends Controller{
public function index(){
// VARS
$template="custom/hello.tpl"; // .tpl location and file
$this->load->model('custom/hello');
$this->template = ''.$template.'';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
}
?>
2)在
admin/view/template/custom/hello.tpl
中创建一个新文件您好。tpl
<?php echo $header; ?>
<div id="content">
<h1>HelloWorld</h1>
<?php
echo 'I can also run PHP too!';
?>
</div>
<?php echo $footer; ?>
3)在
admin/model/custom/hello.php
中创建一个新文件<?php
class ModelCustomHello extends Model {
public function HellWorld() {
$sql = "SELECT x FROM `" . DB_PREFIX . "y`)";
$implode = array();
$query = $this->db->query($sql);
return $query->row['total'];
}
}
?>
4)然后,您需要启用插件,以避免权限被拒绝的错误:
Opencart > Admin > Users > User Groups > Admin > Edit
选择并启用访问权限。
要访问您的页面,请访问
www.yoursite.com/opencart/admin/index.php?route=custom/helloworld
关于php - 如何在opencart中创建自定义管理页面?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10700761/