Post by civanescu » Tue Dec 05, 2017 4:04 pm

Hi, I'm trying to learn to develop a module for my company and I'm stuck in an error. I google 2 days and no results.

I've tried to follow the tutorial from https://code.tutsplus.com/tutorials/fro ... -cms-21873 with upgrades for 2.3 looking in the other modules already there. But no success :(.

I think that a "hello world" tutorial would be useful to avoid stupid questions like mine!

In site installing the module I get a white page, the error in error.log is:

Code: Select all

PHP Fatal error:  Uncaught Error: Class 'Controllerextensionmodulehelloworld' not found in /var/www/html/opencart/system/engine/action.php:43\nStack trace:\n#0 /var/www/html/opencart/system/engine/loader.php(24): Action- PHP Fatal error:  Uncaught Error: Class 'Controllerextensionmodulehelloworld' not found in /var/www/html/opencart/system/engine/action.php:43\nStack trace:\n#0 /var/www/html/opencart/system/engine/loader.php(24): Action->execute(Object(Registry), Array)\n#1 /var/www/html/opencart/admin/controller/extension/extension/module.php(31): Loader->controller('extension/modul...')\n#2 /var/www/html/opencart/system/engine/action.php(51): ControllerExtensionExtensionModule->install()\n#3 /var/www/html/opencart/admin/controller/startup/router.php(26): Action->execute(Object(Registry), Array)\n#4 /var/www/html/opencart/system/engine/action.php(51): ControllerStartupRouter->index()\n#5 /var/www/html/opencart/system/engine/front.php(34): Action->execute(Object(Registry))\n#6 /var/www/html/opencart/system/engine/front.php(29): Front->execute(Object(Action))\n#7 /var/www/html/opencart/system/framework.php(103): Front->dispatch(Object(Action), Object(Action))\n#8 /var/www/html/opencart/system/startup.php(124): require_once('/var/www/html/o...')\n#9 /var/w in /var/www/html/opencart/system/engine/action.php on line 43,,
I believe the problem comes somehow from this: /var/www/html/opencart/admin/controller/extension/extension/module.php(54)
But can't find where should I look.

And if is there any support I attach also the files:

Code: Select all

<?php
class ControllerExtensionModuleHelloworld extends Controller 
{
	private $error = array(); // This is used to set the errors, if any.
 
	public function index() {   // Default function 
		$this->load->language('extension/module/helloworld');
		$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
		$this->load->model('setting/setting'); // Load the Setting Model  (All of the OpenCart Module & General Settings are saved using this Model )
		
 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { // Start If: Validates and check if data is coming by save (POST) method
			$this->model_setting_setting->editSetting('helloworld', $this->request->post);      // Parse all the coming data to Setting Model to save it in database.
			$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save
			$this->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
    } // End If
 
    /*Assign the language data for parsing it to view*/
    $this->data['heading_title'] = $this->language->get('heading_title');
    $this->data['text_enabled'] = $this->language->get('text_enabled');
    $this->data['text_disabled'] = $this->language->get('text_disabled');
    $this->data['text_content_top'] = $this->language->get('text_content_top');
    $this->data['text_content_bottom'] = $this->language->get('text_content_bottom');   
    $this->data['text_column_left'] = $this->language->get('text_column_left');
    $this->data['text_column_right'] = $this->language->get('text_column_right');
    $this->data['entry_code'] = $this->language->get('entry_code');
    $this->data['entry_layout'] = $this->language->get('entry_layout');
    $this->data['entry_position'] = $this->language->get('entry_position');
    $this->data['entry_status'] = $this->language->get('entry_status');
    $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
    $this->data['button_save'] = $this->language->get('button_save');
    $this->data['button_cancel'] = $this->language->get('button_cancel');
    $this->data['button_add_module'] = $this->language->get('button_add_module');
    $this->data['button_remove'] = $this->language->get('button_remove');
     
    /*This Block returns the warning if any*/
    if (isset($this->error['warning'])) {
        $this->data['error_warning'] = $this->error['warning'];
    } else {
        $this->data['error_warning'] = '';
    }
    /*End Block*/
 
    /*This Block returns the error code if any*/
    if (isset($this->error['code'])) {
        $this->data['error_code'] = $this->error['code'];
    } else {
        $this->data['error_code'] = '';
    }
    /*End Block*/
 
    /* Making of Breadcrumbs to be displayed on site*/
    $this->data['breadcrumbs'] = array();
    $this->data['breadcrumbs'][] = array(
        'text'      => $this->language->get('text_home'),
        'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => false
    );
    $this->data['breadcrumbs'][] = array(
        'text'      => $this->language->get('text_module'),
        'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => ' :: '
    );
    $this->data['breadcrumbs'][] = array(
        'text'      => $this->language->get('heading_title'),
        'href'      => $this->url->link('extension/module/helloworld', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => ' :: '
    );
 
    /* End Breadcrumb Block*/
 
    $this->data['action'] = $this->url->link('extension/module/helloworld', 'token=' . $this->session->data['token'], 'SSL'); // URL to be directed when the save button is pressed
    $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'); // URL to be redirected when cancel button is pressed
 
     
    /* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
    if (isset($this->request->post['helloworld_text_field'])) {
        $this->data['helloworld_text_field'] = $this->request->post['helloworld_text_field'];
    } else {
        $this->data['helloworld_text_field'] = $this->config->get('helloworld_text_field');
    }   
    /* End Block*/
 
    $this->data['modules'] = array();
 
    /* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
    if (isset($this->request->post['helloworld_module'])) {
        $this->data['modules'] = $this->request->post['helloworld_module'];
    } elseif ($this->config->get('helloworld_module')) { 
        $this->data['modules'] = $this->config->get('helloworld_module');
    }
    /* End Block*/         
 
    $this->load->model('design/layout'); // Loading the Design Layout Models
    $this->data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
    $this->template = 'extension/module/helloworld.tpl'; // Loading the helloworld.tpl template
    $this->children = array(
        'common/header',
        'common/footer'
    );  // Adding children to our default template i.e., helloworld.tpl 
 
    $this->response->setOutput($this->render()); // Rendering the Output
}

/* Function that validates the data when Save Button is pressed */
    protected function validate() {
 
        /* Block to check the user permission to manipulate the module*/
        if (!$this->user->hasPermission('modify', 'extension/module/helloworld')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }
        /* End Block*/
 
        /* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
        if (!$this->request->post['helloworld_text_field']) {
            $this->error['code'] = $this->language->get('error_code');
        }
        /* End Block*/
 
        /*Block returns true if no error is found, else false if any error detected*/
        if (!$this->error) {
            return true;
        } else {
            return false;
        }   
        /* End Block*/
    }
    /* End Validation Function*/
}

Code: Select all

<?php
// Heading
$_['heading_title']       = 'Salutare World';
 
// Text
$_['text_module']         = 'Moduleeee';
$_['text_success']        = 'Successuri: You have modified module Hello World!';
$_['text_content_top']    = 'Content Sus Top';
$_['text_content_bottom'] = 'Content Jos Bottom';
$_['text_column_left']    = 'Column Stanga Left';
$_['text_column_right']   = 'Column Dreapta Right';
 
// Entry
$_['entry_code']          = 'Hello World Start-up coding Code:';
$_['entry_layout']        = 'Leiaut:';
$_['entry_position']      = 'Pozision:';
$_['entry_status']        = 'Status:';
$_['entry_sort_order']    = 'Ordine:';
 
// Error
$_['error_permission']    = 'Atentie -  Warning: You do not have permission to modify module Hello World!';
$_['error_code']          = 'Code Required';
?> 

Code: Select all

<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="form">
          <tr>
            <td><span class="required">*</span> <?php echo $entry_code; ?></td>
            <td><textarea name="helloworld_text_field" cols="40" rows="5"><?php echo $helloworld_text_field; ?></textarea>
              <?php if ($error_code) { ?>
              <span class="error"><?php echo $error_code; ?></span>
              <?php } ?></td>
          </tr>
        </table>
		
<table id="module" class="list">
          <thead>
            <tr>
              <td class="left"><?php echo $entry_layout; ?></td>
              <td class="left"><?php echo $entry_position; ?></td>
              <td class="left"><?php echo $entry_status; ?></td>
              <td class="right"><?php echo $entry_sort_order; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $module_row = 0; ?>
          <?php foreach ($modules as $module) { ?>
          <tbody id="module-row<?php echo $module_row; ?>">
            <tr>
              <td class="left"><select name="helloworld_module[<?php echo $module_row; ?>][layout_id]">
                  <?php foreach ($layouts as $layout) { ?>
                  <?php if ($layout['layout_id'] == $module['layout_id']) { ?>
                  <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
              <td class="left"><select name="helloworld_module[<?php echo $module_row; ?>][position]">
                  <?php if ($module['position'] == 'content_top') { ?>
                  <option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
                  <?php } else { ?>
                  <option value="content_top"><?php echo $text_content_top; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'content_bottom') { ?>
                  <option value="content_bottom" selected="selected"><?php echo $text_content_bottom; ?></option>
                  <?php } else { ?>
                  <option value="content_bottom"><?php echo $text_content_bottom; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'column_left') { ?>
                  <option value="column_left" selected="selected"><?php echo $text_column_left; ?></option>
                  <?php } else { ?>
                  <option value="column_left"><?php echo $text_column_left; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'column_right') { ?>
                  <option value="column_right" selected="selected"><?php echo $text_column_right; ?></option>
                  <?php } else { ?>
                  <option value="column_right"><?php echo $text_column_right; ?></option>
                  <?php } ?>
                </select></td>
              <td class="left"><select name="helloworld_module[<?php echo $module_row; ?>][status]">
                  <?php if ($module['status']) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
              <td class="right"><input type="text" name="helloworld_module[<?php echo $module_row; ?>][sort_order]" value="<?php echo $module['sort_order']; ?>" size="3" /></td>
              <td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
            </tr>
          </tbody>
          <?php $module_row++; ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td colspan="4"></td>
              <td class="left"><a onclick="addModule();" class="button"><?php echo $button_add_module; ?></a></td>
            </tr>
          </tfoot>
        </table>
      </form>
    </div>
  </div>
</div>

<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;
 
function addModule() {    
    html  = '<tbody id="module-row' + module_row + '">';
    html += '  <tr>';
    html += '    <td class="left"><select name="helloworld_module[' + module_row + '][layout_id]">';
    <?php foreach ($layouts as $layout) { ?>
    html += '      <option value="<?php echo $layout['layout_id']; ?>"><?php echo addslashes($layout['name']); ?></option>';
    <?php } ?>
    html += '    </select></td>';
    html += '    <td class="left"><select name="helloworld_module[' + module_row + '][position]">';
    html += '      <option value="content_top"><?php echo $text_content_top; ?></option>';
    html += '      <option value="content_bottom"><?php echo $text_content_bottom; ?></option>';
    html += '      <option value="column_left"><?php echo $text_column_left; ?></option>';
    html += '      <option value="column_right"><?php echo $text_column_right; ?></option>';
    html += '    </select></td>';
    html += '    <td class="left"><select name="helloworld_module[' + module_row + '][status]">';
    html += '      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
    html += '      <option value="0"><?php echo $text_disabled; ?></option>';
    html += '    </select></td>';
    html += '    <td class="right"><input type="text" name="helloworld_module[' + module_row + '][sort_order]" value="" size="3" /></td>';
    html += '    <td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
    html += '  </tr>';
    html += '</tbody>';
     
    $('#module tfoot').before(html);
     
    module_row++;
}
//--></script>

<?php echo $footer; ?>
Last edited by civanescu on Fri Dec 08, 2017 9:00 pm, edited 1 time in total.

Newbie

Posts

Joined
Wed Dec 09, 2015 6:28 pm

Post by straightlight » Tue Dec 05, 2017 10:11 pm

According to your provided error message, there are no issues with the module extension file itself. The issue is with your module's filename and / or the title from the class: Controllerextensionmodulehelloworld.

From the provided module above, we do see: ControllerExtensionModuleHelloworld . Which means, your filename must be created as: helloworld.php . If it is rather created as: hello_world.php, then you need to assign the class name like this: ControllerExtensionModuleHelloWorld . It is simply common sense.

In addition, the entire code does not need to be posted for one error message along with your unposted OC version.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by civanescu » Wed Dec 06, 2017 2:39 pm

I'm sorry for posting the entire code, but I kept reading the code line by line and didn't find the source of problem.
But... my file is called helloworld, you do recommend to change the class to ControllerExtensionModuleHelloWorld and the files to hello_world ?

And actually after that error in error.log the module appear with loaded. But when I try to click on edit I get this error:

Code: Select all

Fatal error: Uncaught Error: Class 'Controllerextensionmodulehelloworld' not found in /var/www/html/opencart/system/engine/action.php:43 Stack trace: #0 /var/www/html/opencart/admin/controller/startup/router.php(26): Action->execute(Object(Registry), Array) #1 /var/www/html/opencart/system/engine/action.php(51): ControllerStartupRouter->index() #2 /var/www/html/opencart/system/engine/front.php(34): Action->execute(Object(Registry)) #3 /var/www/html/opencart/system/engine/front.php(29): Front->execute(Object(Action)) #4 /var/www/html/opencart/system/framework.php(103): Front->dispatch(Object(Action), Object(Action)) #5 /var/www/html/opencart/system/startup.php(124): require_once('/var/www/html/o...') #6 /var/www/html/opencart/admin/index.php(19): start('admin') #7 {main} thrown in /var/www/html/opencart/system/engine/action.php on line 43
Thank you in advance...

Newbie

Posts

Joined
Wed Dec 09, 2015 6:28 pm

Post by straightlight » Wed Dec 06, 2017 10:43 pm

The filename seem to be fine. Although, you'd need to change:

Code: Select all

Controllerextensionmodulehelloworld
to:

Code: Select all

ControllerExtensionModuleHelloworld

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by civanescu » Thu Dec 07, 2017 2:46 pm

Thanks Straightlight, but can't find where is this definition. Inside my file the class is written correctly! Only in error appear with all chars low! I'm really lost!
straightlight wrote:
Wed Dec 06, 2017 10:43 pm
The filename seem to be fine. Although, you'd need to change:

Code: Select all

Controllerextensionmodulehelloworld
to:

Code: Select all

ControllerExtensionModuleHelloworld

Newbie

Posts

Joined
Wed Dec 09, 2015 6:28 pm

Post by civanescu » Thu Dec 07, 2017 5:34 pm

Ok, I get to the next step. Look on other modules line by line. :)
The installation worked ok after changed the following:
Instead of: $this->load->model('setting/setting'); I used $this->load->model('extension/module');
Instead of: $this->error['code']; you have to use $this->error['name'];
At /*Assign the language data for parsing it to view*/, instead of $this->$data[...] I used only $data

Now the install/uninstall worked ok. My new errors are:

Code: Select all

From ERROR.LOG PHP Fatal error:  Uncaught Error: Call to undefined method ControllerExtensionModuleHelloworld::render() in /var/www/html/opencart/admin/controller/extension/module/helloworld.php:109\nStack trace:\n#0 /var/www/html/opencart/system/engine/action.php(51): ControllerExtensionModuleHelloworld->index()\n#1 /var/www/html/opencart/admin/controller/startup/router.php(26): Action->execute(Object(Registry), Array)\n#2 /var/www/html/opencart/system/engine/action.php(51): ControllerStartupRouter->index()\n#3 /var/www/html/opencart/system/engine/front.php(34): Action->execute(Object(Registry))\n#4 /var/www/html/opencart/system/engine/front.php(29): Front->execute(Object(Action))\n#5 /var/www/html/opencart/system/framework.php(103): Front->dispatch(Object(Action), Object(Action))\n#6 /var/www/html/opencart/system/startup.php(124): require_once('/var/www/html/o...')\n#7 /var/www/html/opencart/admin/index.php(19): start('admin')\n#8 {main}\n  thrown in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 109, 
And from webpage:

Code: Select all

Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 45Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 60Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 61Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 66Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 71Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 79Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 80Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 87Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 91Notice: Indirect modification of overloaded property ControllerExtensionModuleHelloworld::$data has no effect in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 102
Fatal error: Uncaught Error: Call to undefined method ControllerExtensionModuleHelloworld::render() in /var/www/html/opencart/admin/controller/extension/module/helloworld.php:109 Stack trace: #0 /var/www/html/opencart/system/engine/action.php(51): ControllerExtensionModuleHelloworld->index() #1 /var/www/html/opencart/admin/controller/startup/router.php(26): Action->execute(Object(Registry), Array) #2 /var/www/html/opencart/system/engine/action.php(51): ControllerStartupRouter->index() #3 /var/www/html/opencart/system/engine/front.php(34): Action->execute(Object(Registry)) #4 /var/www/html/opencart/system/engine/front.php(29): Front->execute(Object(Action)) #5 /var/www/html/opencart/system/framework.php(103): Front->dispatch(Object(Action), Object(Action)) #6 /var/www/html/opencart/system/startup.php(124): require_once('/var/www/html/o...') #7 /var/www/html/opencart/admin/index.php(19): start('admin') #8 {main} thrown in /var/www/html/opencart/admin/controller/extension/module/helloworld.php on line 109
After finishing this project I'll propose to write it somewhere where everybody can see the tutorial :).

Newbie

Posts

Joined
Wed Dec 09, 2015 6:28 pm

Post by straightlight » Thu Dec 07, 2017 10:21 pm

The tutorial already exists on the forum. However, you are requesting a change regarding an old contribution into a newer version of Opencart which is not mentioned on the topic subject. The $this->render() no longer exists starting in v2.x releases of Opencart. It is rather used with:

Code: Select all

$this->response->setOutput($this->load->view('your_last_path/your_template', $data));
instead.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by civanescu » Fri Dec 08, 2017 5:42 pm

SOLVED!

After studying more, you also have to change from:

Code: Select all

/*    $this->template = 'extension/module/helloworld.tpl'; // Loading the helloworld.tpl template
    $this->children = array(
        'common/header',
        'common/footer'
    );  // Adding children to our default template i.e., helloworld.tpl 
     $this->response->setOutput($this->render()); // Rendering the Output  */
to

Code: Select all

		$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('extension/module/helloworld', $data));

Newbie

Posts

Joined
Wed Dec 09, 2015 6:28 pm
Who is online

Users browsing this forum: No registered users and 37 guests