Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

php - Adding an admin page on OpenCart version 2

I am havin a problem adding an admin page to Opencart2, and following the answers on pretty much identical questions on SO do no help, so I beleive the problem is specific to OC2.

Following the answer at this question I still get the error message "Fatal error: Call to undefined method ControllerCustomHelloWorld::render() in C:websitesweddingshoponlineshopadmincontrollercustomhelloworld.php on line 13. Any help would be much appreciated, as I have been going around in circles.

Thank you.

PS Reverting to a previous version of OC is not valid response, albeit a good one.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The difference between page rendering in OC < 2.0 and OC 2.0 are only few but you have to be aware of them.

1. $data

In OC < 2.0 you would do this:

$this->data['text_button_save'] = $this->language->get('text_button_save');

while in OC 2.0 it is only $data, i.e.

$data['text_button_save'] = $this->language->get('text_button_save');

that is passed over to the $this->load->view() method as an argument, e.g.:

$this->response->setOutput($this->load->view('catalog/category_list.tpl', $data));

2. $this->render()

is gone. Now you are calling $this->load->view('catalog/category_list.tpl', $data) instead.

3. $this->children

is gone. Now the template child modules' positions are instantiated as part of template properties while you have to call their controllers manually (WHY?):

$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');

I was thinking why the hell were these changes required. What has been improved? Did they want the developers to write less code? Is it now more following the OOP, MVC, WTF (sorry) principles? And got the answer: NO (or nothing to the first one).

We still have to load the translations (I mean, we still have to load each single string translation). And gettext is out there for more than 8 years...

Instead of short $this->response->setOutput($this->render()); we now have to call much longer (and incomprehensible) $this->response->setOutput($this->load->view('catalog/category_form.tpl', $data));. Why can't we just do this: $this->render('catalog/category_form.tpl', $data); ???

I personally think OC 2.0 is the same excrement (from the developers perspective) as it was before. They just changed the packaging. But, honestly, there are even bigger excrements out there, that's why I'm stuck with OpenCart :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...