问题
I have follow this answer Check module position in OpenCart 2.0 and it is working fine When add it code direct in core file.
But, when, this same code (Step 3) add via Vqmod (without change core file). So, It is not work. Get error ( Notice: Undefined index: position in.... )
Our Vqmod Code.
<file path="catalog/controller/common/" name="content_top.php,content_bottom.php,content_right.php,content_left.php">
<operation>
<search position="after">
<![CDATA[$setting_info = $this->model_extension_module->getModule($part[1]);]]>
</search>
<add>
<![CDATA[$setting_info['position'] = basename(__FILE__, '.php');]]>
</add>
</operation>
</file>
I am used OpenCart Version 2.0.1.1
How to fix it?
=== Update ===
changed code in vqcache file.
if (isset($part[1])) {
$setting_info = $this->model_extension_module->getModule($part[1]);
if(!isset($setting_info['position'])){
$setting_info['position'] = basename(__FILE__, '.php');
}
if ($setting_info && $setting_info['status']) {
$data['modules'][] = $this->load->controller('module/' . $part[0], $setting_info);
}
When module Enabled in Left/right column. So, do get below error.
Notice: Undefined index: position in C:\......\template\module\featured.tpl on line 1
When module Enabled in Top/bottom column. So, do nothing display.
回答1:
Well i have not been following OpenCart for a while now but i think i can help you with your question as i seem to recall a similar situation.
First of all i suggest you always check the vqcache folder for the code that is outputted so you can have a more thorough look.
Secondly the issue seems to be that adding it via vqmod triggers the check for the variable first that it is actually not initialized beforehand but at that moment and thus you get an " Undefined index" error. the solution should be replacing:
<![CDATA[$setting_info['position'] = basename(__FILE__, '.php');]]>
with:
<![CDATA[
if(!isset($setting_info['position'])){
$setting_info['position'] = basename(__FILE__, '.php');
}
]]>
The general idea is a check for the variable if it exists before hand should be the solution. If not you should debug the generated file in your vqcache folder and see what is the actual rendered code.
I wish I could help you more, but I haven't used OpenCart for a long time (especially the new versions).
来源:https://stackoverflow.com/questions/27717502/get-error-when-code-add-via-vqmod