Gav*_*son 5 php opencart opencart2.x
我在向Opencart2添加管理页面时遇到了问题,并且关于SO的几乎完全相同的问题的答案没有帮助,所以我相信这个问题是特定于OC2的.
在这个问题的答案后,我仍然在第13行的C:\ websites\weddingshoponline\shop\admin\controller\custom\helloworld.php中收到错误消息" 致命错误:调用未定义的方法ControllerCustomHelloWorld :: render().任何非常感谢帮助,因为我一直在圈子里走来走去.
谢谢.
PS恢复到以前版本的OC并不是有效的响应,尽管是一个好的响应.
sha*_*yyx 20
OC <2.0和OC 2.0中的页面呈现之间的区别很少,但您必须了解它们.
$data在OC <2.0中你会这样做:
$this->data['text_button_save'] = $this->language->get('text_button_save');
Run Code Online (Sandbox Code Playgroud)
而在OC 2.0中它只是$data,即
$data['text_button_save'] = $this->language->get('text_button_save');
Run Code Online (Sandbox Code Playgroud)
$this->load->view()作为参数传递给方法,例如:
$this->response->setOutput($this->load->view('catalog/category_list.tpl', $data));
Run Code Online (Sandbox Code Playgroud)
$this->render()离开了.现在你打电话$this->load->view('catalog/category_list.tpl', $data)来.
$this->children离开了.现在模板子模块的位置被实例化为模板属性的一部分,而你必须手动调用它们的控制器(为什么?):
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
Run Code Online (Sandbox Code Playgroud)
我在想为什么这些变化到底需要什么.有哪些改进?他们是否希望开发人员编写更少的代码?它现在更符合OOP,MVC,WTF(抱歉)原则吗?得到答案:不(或第一个没什么).
我们仍然需要加载翻译(我的意思是,我们仍然需要加载每个单独的字符串翻译).并且gettext在那里超过8年......
取而代之的短$this->response->setOutput($this->render());,我们现在必须调用更长(和不可理解的)$this->response->setOutput($this->load->view('catalog/category_form.tpl', $data));.为什么我们不能这样做:$this->render('catalog/category_form.tpl', $data);???
我个人认为OC 2.0与以前一样(从开发人员的角度来看)是相同的排泄物.他们只是改变了包装.但是,老实说,那里有更大的排泄物,这就是为什么我被OpenCart困住了:-)
详细阐述了shadyyx对问题的回答,以及我工作的代码......我并不是说它是完美的,只是它有效.
管理员\控制器\定制\ helloworld.php
<?php
class ControllerCustomHelloWorld extends Controller
{
private $error = array();
public function index()
{
$this->load->model('setting/setting');
$this->load->language('custom/helloworld');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('custom/helloworld.tpl', $data));
}
}
?>
Run Code Online (Sandbox Code Playgroud)
管理员\语言\英语\定制\ helloworld.php
<?php
// Heading
$_['heading_title'] = 'My First Admin Page...';
// Text
$_['text_module'] = 'Modules';
$_['text_success'] = 'Success: You have modified module account!';
$_['text_content_top'] = 'Content Top';
$_['text_content_bottom'] = 'Content Bottom';
$_['text_column_left'] = 'Column Left';
$_['text_column_right'] = 'Column Right';
// Entry
$_['entry_layout'] = 'Layout:';
$_['entry_position'] = 'Position:';
$_['entry_status'] = 'Status:';
$_['entry_sort_order'] = 'Sort Order:';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify module account!';
?>
Run Code Online (Sandbox Code Playgroud)
管理员\型号\定制\ helloworld.php
<?php
class ModelCustomHelloWorld extends Model
{
public function HelloWorld()
{
$sql = "SELECT * FROM " . DB_PREFIX . "category_description";
$implode = array();
$query = $this->db->query($sql);
return $query->rows;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
管理\查看\模板\定制\ helloworld.php
<?php echo $header; ?><?php echo $column_left; ?>
<div id='content'>
<h1><?php echo $heading_title; ?></h1>
<?phpecho 'I can also create a custom admin page.!'<br/>; ?>
<?php print_r($my_results);?>
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</div>
<?php echo $footer; ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10069 次 |
| 最近记录: |