Jump to content

My first module, "MyModule" won't work: "class missing"


Recommended Posts

Hello,

 

I am new at module developing for Prestshop and just started following the official documentation site for module developing (http://doc.prestasho...estaShop+module). I copied the "MyModule" example code to a php file into the modules directory as follows:

 

/modules/mymodule/mymodule.php

/modules/mymodule/logo.gif

 

I'm testing on a Prestashop 1.4 fresh install on a XAMPP system under Windows 7 x64. Happens that when I open the Modules tab, an error is triggered displaying this message:

 

The following module(s) couldn't be loaded:

  1. mymodule (parse error in /modules/mymodule/mymodule.php)
  2. mymodule (class missing in /modules/mymodule/mymodule.php)

 

Which looks pretty unuseful, if I exec the file without the first if and declaring class Module {}, it doesn't throw any error.

 

I have been searching in Google but nothing useful came from that. Also, it's the example in the docs, it must work, right? :| just in case, this is my code:

 

<?php
if (!defined('_PS_VERSION_'))
 exit;

class MyModule extends Module
 {
 public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'Test';
$this->version = 1.0;
$this->author = 'Firstname Lastname';
$this->need_instance = 0;

parent::__construct();

$this->displayName = $this->l('My module');
$this->description = $this->l('Description of my module.');
}

 public function install()
{
if (parent::install() == false)
  return false;
return true;
}
 }
?>

 

Any idea? Which is the best course of action as of right now? Can't think of anything, and the error message is not helping tough.

 

Thanks in advance.

Link to comment
Share on other sites

this is likely not very useful for you, but i copied your code above and installed it on my test server (WAMP prestasgop v1.4.6.2) and it installed properly.

 

what you have done is correct, so i'm not sure how best to help you or advise to give. here are the steps i took to install that module, perhaps the steps you are taking are different?

 

1) create a folder under modules called mymodule

2) create a file called mymodule.php in the modules/mymodule folder

3) edit the mymodule.php file, and copy the contents of the code above as is

4) open the back office and navigate to the modules section

5) search for mymodule module, and click install

Link to comment
Share on other sites

Thanks for your reply. That's what I have done. I have also tried installing the module via the "Install new module" (zip upload) option in the back office, I could be doing something wrong but even this way it triggers the error.

 

I am using Prestashop 1.4.7.2, maybe documentation has been written for a previous version (like 1.4.6.x)? Could it be a platform (Windows, XAMPP) issue?

Link to comment
Share on other sites

I have it.

 

After thinking for a while I took a look at the file encoding with Notepad++. The standard modules which come with Prestashop were all encoded with ANSI, and mine was with UTF-8. So, converting from UTF-8 to ANSI fixed the problem. So fast, so good.

 

Something about this must be mentioned in the documentation I think.

 

Anyway, thanks for your help bellini13.

 

Regards.

  • Like 4
Link to comment
Share on other sites

  • 1 year later...

Thank you so much, you saved my day!! ;)

 

I have it.

After thinking for a while I took a look at the file encoding with Notepad++. The standard modules which come with Prestashop were all encoded with ANSI, and mine was with UTF-8. So, converting from UTF-8 to ANSI fixed the problem. So fast, so good.

Something about this must be mentioned in the documentation I think.

Anyway, thanks for your help bellini13.

Regards.

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

I have it.

 

After thinking for a while I took a look at the file encoding with Notepad++. The standard modules which come with Prestashop were all encoded with ANSI, and mine was with UTF-8. So, converting from UTF-8 to ANSI fixed the problem. So fast, so good.

 

Something about this must be mentioned in the documentation I think.

 

Anyway, thanks for your help bellini13.

 

Regards.

 

You understand the problem: the file encoding. I'm writing a module and have the same issue. But if i convert to ANSI, the validator in addonns.prestashop.com doesn't accept the module. It says that UTF-8 is needed.

 

I solve the problem converting files in UTF-8 without BOM in notepad++.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...