I created a card module called "card". I created "card.php & card.tpl" files in
- language\english\extension\module
- extension\module
- template\kottu\module
I used "" in layout.tpl to display the module and I am getting the following message.
Notice: Undefined variable: card in /home/handy/www/kottu/catalog/template/kottu/layout.tpl on line 44
Any help is appreciated.
Bharat
- language\english\extension\module
- extension\module
- template\kottu\module
I used "" in layout.tpl to display the module and I am getting the following message.
Notice: Undefined variable: card in /home/handy/www/kottu/catalog/template/kottu/layout.tpl on line 44
Any help is appreciated.
Bharat
I moved paypal, master and visa card images from footer to the column on the left to create space for footer text.
I tried the following in "catalog/extension/module/card.php" and it didn't work.
locator->get('config');
$language =& $this->locator->get('language');
if ($config->get('card_status')) {
$language->load('extension/module/card.php');
$view = $this->locator->create('template');
$view->set('card', $variable);
return $view->fetch('module/card.tpl');
}
}
}
?>
I tried the following in "catalog/extension/module/card.php" and it didn't work.
locator->get('config');
$language =& $this->locator->get('language');
if ($config->get('card_status')) {
$language->load('extension/module/card.php');
$view = $this->locator->create('template');
$view->set('card', $variable);
return $view->fetch('module/card.tpl');
}
}
}
?>
Ok, extensions have a few extra steps.
First are you doing this in 1.0 or 0.7.x? 1.0 really isn't ready for development and it doesn't actually support modules since daniel hasn't added that back in. So just give me the OK and I will move this to the 0.x forum.
Back to the point, and assuming 0.7.x...
Step 1. To create a new module, you will need to create the follow file structures.
Step 2. We will start with the front-end files first.
Edit catalog/extension/module/xxx.php. This is where the main controlling code goes. all the calculations, or data is handled here.
Using footer.php file as our example, you can see the only real code that is being done here is to pass a variable from the controller to the view called: text_powered_by. This variable is set with the content that is pulled from the language file referred to by a variable there with the same name. Change this to be code for what you want to do.
Edit catalog/language/english/extension/module/xxx.php. Everywhere you call a reference to the language file, for example: $view->set('text_powered_by', $language->get('text_powered_by'));, you need to create a matching name in the language file with the message you want:
(from: catalog/language/english/extension/module/footer.php):
Save the file and close it.
Step 4. In the main extension, you needed to create a $view->set for every variable you wanted the template to be able to display. Now you need to match those corresponding variable names in the template.
Edit catalog/template/default/module/xxx.tpl.
Examining the first part of our example: $view->set('text_powered_by', $language->get('text_powered_by'));
Now the view can use the variable $text_powered_by.
(from: catalog/template/default/module/footer.tpl):
Make the needed changes.
Save the file and close.
Step 5. Edit catalog/template/default/layout.tpl
Follow the existing structure for the other modules.
Add the following block where you want it:
Step 6. First you will need to add it to the database via the admin panel. This is somewhat of a mundane process, as it would be best if the code could just read the directory and find the new files (planned for a future release). Take a look at the existing footer module in the admin area under "Extensions->Module". Click the "update" button (icon looks like a notepad) and click the 'data' tab. You should see the configuration settings that look something like this:
Using that example. Go back to the main "Extensions->Modules" menu and click the "Insert" button at the top.
- Enter the name of the module
- enter the data information using the example from above.
- Save it.
Step 7. Edit the new admin/extension/module/xxx.php file and change all places you see "footer" with the new name. Unless you have some additional settings (advanced configurations only), this file is basically generic template.
Save & close.
Step 8. Edit admin/language/english/controller/module_catalog_xxx.php
Once again, change all places that say "footer" to the new name
Save & close.
Step 9. Edit admin/template/default/content/module_catalog_xxx.tpl
And again, change all places from "footer" to the new name.
Save & close.
Step 10. Finally, go back to the "Extensions->Module" page you should be back at the main modules screen again. Click the "wrench" or "spanner" icon, and enable the module.
Now you should have a working module!
First are you doing this in 1.0 or 0.7.x? 1.0 really isn't ready for development and it doesn't actually support modules since daniel hasn't added that back in. So just give me the OK and I will move this to the 0.x forum.
Back to the point, and assuming 0.7.x...
Step 1. To create a new module, you will need to create the follow file structures.
I would clone one of the simpler existing modules like "footer", and just modify the files for the new module.Front-end files:
- catalog/extension/module/xxx.php
- catalog/language/english/extension/module/xxx.php
- catalog/template/default/module/xxx.tpl
Back-end files:
- admin/controller/module_catalog_xxx.php
- admin/extension/module/xxx.php
- admin/language/english/controller/module_catalog_xxx.php
- admin/template/default/content/module_catalog_xxx.tpl
Step 2. We will start with the front-end files first.
Edit catalog/extension/module/xxx.php. This is where the main controlling code goes. all the calculations, or data is handled here.
Using footer.php file as our example, you can see the only real code that is being done here is to pass a variable from the controller to the view called: text_powered_by. This variable is set with the content that is pulled from the language file referred to by a variable there with the same name. Change this to be code for what you want to do.
Step 3. Now that you have your code, you need to add the supporting context to the language file.locator->get('config');
$language =& $this->locator->get('language');
if ($config->get('footer_status')) {
$language->load('extension/module/footer.php');
$view = $this->locator->create('template');
$view->set('text_powered_by', $language->get('text_powered_by'));
return $view->fetch('module/footer.tpl');
}
}
}
?>
Edit catalog/language/english/extension/module/xxx.php. Everywhere you call a reference to the language file, for example: $view->set('text_powered_by', $language->get('text_powered_by'));, you need to create a matching name in the language file with the message you want:
(from: catalog/language/english/extension/module/footer.php):
Notice the language file can support full html, a great place to handle the links and style.$_['text_powered_by'] = 'Powered by OpenCartCopyright © '.date('Y');
Save the file and close it.
Step 4. In the main extension, you needed to create a $view->set for every variable you wanted the template to be able to display. Now you need to match those corresponding variable names in the template.
Edit catalog/template/default/module/xxx.tpl.
Examining the first part of our example: $view->set('text_powered_by', $language->get('text_powered_by'));
Now the view can use the variable $text_powered_by.
(from: catalog/template/default/module/footer.tpl):
This is where the majority of your html will go, using php tags to reference the preset view variables
Make the needed changes.
Save the file and close.
Step 5. Edit catalog/template/default/layout.tpl
Follow the existing structure for the other modules.
Add the following block where you want it:
Now we have our front-end files done. But we need to add it to the admin area for enable/disable control and add it to the database.
Step 6. First you will need to add it to the database via the admin panel. This is somewhat of a mundane process, as it would be best if the code could just read the directory and find the new files (planned for a future release). Take a look at the existing footer module in the admin area under "Extensions->Module". Click the "update" button (icon looks like a notepad) and click the 'data' tab. You should see the configuration settings that look something like this:
Code: Select all
Code: footer
Directory: module
Filename: footer.php
Controller: module_catalog_footer
- Enter the name of the module
- enter the data information using the example from above.
- Save it.
Step 7. Edit the new admin/extension/module/xxx.php file and change all places you see "footer" with the new name. Unless you have some additional settings (advanced configurations only), this file is basically generic template.
Save & close.
Step 8. Edit admin/language/english/controller/module_catalog_xxx.php
Once again, change all places that say "footer" to the new name
Save & close.
Step 9. Edit admin/template/default/content/module_catalog_xxx.tpl
And again, change all places from "footer" to the new name.
Save & close.
Step 10. Finally, go back to the "Extensions->Module" page you should be back at the main modules screen again. Click the "wrench" or "spanner" icon, and enable the module.
Now you should have a working module!
Last edited by Qphoria on Wed Oct 22, 2008 1:57 am, edited 1 time in total.
Dang, Q. Your post sure would look good in the "How to write extensions" section of the OpenCart developer's wiki...
... if there was an OpenCart developer's wiki.
... if there was an OpenCart developer's wiki.
Hello Qphoria,
I tried everything you posted step by step 4 times. I had to reinstall opencart everytime as I am getting the following message.
_________________
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
_________________
In Step 1 -
In the front-end files list you mentioned: "- catalog/language/english/extension/module/xxx.tpl
"
. But there are not TPL files in that folder. There are only PHP files. So I copied "footer.php". file and renamed it to "card.php".
For others, I copied the appropriate footer file and renamed.
In Step 6 -
I used the following to create a module
Code: card
Directory: module
Filename: card.php
Controller: module_catalog_card
When I refreshed the page after creating the module, I got the following error message.
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
Step 7 -
No new file was created in "admin/extension/module/"
There was no wrench icon but there was a + sign in the extensions->modules of admin menu. When I clicked on it I got the follwoing error message.
Permission Denied!
You do not have permission to access this page, please refer to your system administrator.
Am I doing anything wrong?
I tried everything you posted step by step 4 times. I had to reinstall opencart everytime as I am getting the following message.
_________________
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
_________________
In Step 1 -
In the front-end files list you mentioned: "- catalog/language/english/extension/module/xxx.tpl
"
. But there are not TPL files in that folder. There are only PHP files. So I copied "footer.php". file and renamed it to "card.php".
For others, I copied the appropriate footer file and renamed.
In Step 6 -
I used the following to create a module
Code: card
Directory: module
Filename: card.php
Controller: module_catalog_card
When I refreshed the page after creating the module, I got the following error message.
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
Step 7 -
No new file was created in "admin/extension/module/"
There was no wrench icon but there was a + sign in the extensions->modules of admin menu. When I clicked on it I got the follwoing error message.
Permission Denied!
You do not have permission to access this page, please refer to your system administrator.
Am I doing anything wrong?
Sorry, typo. But you figured it out. (I fixed in in my post now)bharat wrote: In Step 1 -
In the front-end files list you mentioned: "- catalog/language/english/extension/module/xxx.tpl
"
. But there are not TPL files in that folder. There are only PHP files. So I copied "footer.php". file and renamed it to "card.php".
For others, I copied the appropriate footer file and renamed.
Sorry, forgot to add that to the file structure from step 1. You should copy thebharat wrote: In Step 6 -
Step 7 -
admin/extension/module/footer.php
to
admin/extension/module/xxx.php
This problem is gone in 0.7.9 but you need to also allow access to the new files you created in the Admin->Configuration->UserGroups area for Top Administratorsbharat wrote: Permission Denied!
You do not have permission to access this page, please refer to your system administrator.
I am still getting the same error message:
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
after step 6.
Is it possible to make the module show up only in certain pages and hide in others?
Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
after step 6.
Is it possible to make the module show up only in certain pages and hide in others?
Firstly, check library\application\controller.php to make sure that the execute() function has the following line... exactly
Secondly, check that the first line of catalog\extension\module\card.php is
Finally, if you have a look at the suggestions I have made to implement the Featured/Specials contribution then you will see one way to control what modules are displayed from any controller.
Code: Select all
$controller = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', NULL, $action['class']);
Code: Select all
class ModuleCard extends Controller {
Ah yea.. that would be a very important step that I missed in my tutorial..bruce wrote: Secondly, check that the first line of catalog\extension\module\card.php isCode: Select all
class ModuleCard extends Controller {
bharat - Did you solve your problems? How?
I followed the instructions for a new module "student" and got the same result ( v0.7.8 )
- The new Student Module appears on the extensions page WITH a plus sign but WITHOUT the spanner
- When I try to install, I get the "Permission Denied!" message
- Under Admin > Configuration > Users > User Group > Top Administrator, the new module DOES NOT appear
- The rest of Administration appears to be functioning properly.
If I navigate to the shop/ I get a syntax error from catalog/extension/module/student.php. The student.php code doesn't generate any errors in my editor. Is that what's preventing the module from displaying for Administration? .... Or is that my next problem to solve? :-)
I followed the instructions for a new module "student" and got the same result ( v0.7.8 )
- The new Student Module appears on the extensions page WITH a plus sign but WITHOUT the spanner
- When I try to install, I get the "Permission Denied!" message
- Under Admin > Configuration > Users > User Group > Top Administrator, the new module DOES NOT appear
- The rest of Administration appears to be functioning properly.
If I navigate to the shop/ I get a syntax error from catalog/extension/module/student.php. The student.php code doesn't generate any errors in my editor. Is that what's preventing the module from displaying for Administration? .... Or is that my next problem to solve? :-)
I solved my own problem.
The syntax error was not related to the problem.
The problem was caused by not creating the following file:
admin/controller/module_catalog_student.php
It looks like this step is missing from the instructions .... in the wiki!
The syntax error was not related to the problem.
The problem was caused by not creating the following file:
admin/controller/module_catalog_student.php
It looks like this step is missing from the instructions .... in the wiki!
Who is online
Users browsing this forum: No registered users and 73 guests