Hi there,
I am trying to figure out how to write a module for Oxid Commerce System, till now everything was going perfectly, but I have stumbled upon a Problem and can’t find a solution for it…
I just wanna do a simple echo within my own class, but the Oxid System doesn’t load my file I think…
this is my metadata.php:
<?php
/**
* Metadata version
*/
$sMetadataVersion = '1.0';
/**
* Module information
*/
$aModule = array(
'id' => 'x_module',
'title' => 'Module Name',
'description' => 'Module Description',
'thumbnail' => 'picture.png',
'version' => '0.9.8',
'author' => '***',
'url' => 'http://www.*****.de',
'email' => '******@****.com',
'extend' => array(),
'files' => array(
'x_module' => 'x_module/core/x_module.php',
),
);
x_module/core/x_module.php
<?php
class x_module
{
public function __construct(){
echo "test"; // just a simple echo nothing more
}
}
Also when I look between the declared classes it is not between it…
I use print_r(get_declared_classes()); to check out which classes are declared…
Any help is welcome… thnx
The class will not be loaded until it is instantiated somewhere in the code with
oxnew ("x_module");
thnx for the quick response
I tried the following and it still won’t echo anything and the class still isn’t loaded, am I missing something important here?
class x_module
{
public function __construct(){
oxnew("x_module"); // first I tried this
$test = oxnew("x_module"); // then this
echo "test";
}
}
I really need to figure this out, I am like 3 days going around with this one thing and kinda getting stressed about this… any help is apreciated
before this I had some trouble with the tpl/blocks aswell, but after a while I discovered that if the module is activated once the “blocks” part in the metadata.php inserts the SQL queries only once and it stays definite… so changes wouldn’t take any effect only would activate or deactivate it… I had to remove the rows to make any changes…
Have you tried to call your module with http://yourdomain.com/index.php?cl=x_module ? Remove the “oxnew” parts before you try this.
Hi jschindler thanx for the reply
I just tried it out and it shows an echo on a complete white page, without any template…
I also checked the declared classes, and its the same as on other pages except for that mine is declared aswell
does that mean it works? but on all the other pages it wont show anything or the class ain
t active… I want it to work on all pages, in the tutorial it said that the files are loaded automatically, so I don’t need to make any changes right?
read a bit about mvc and have a look at the OXID’s core classes.
and i suggest to start module development by creating views and not models, its a bit easier
If you want code in your module to be executed, you’ve got to hook it in the existing code somewhere, or it will just lie around and will never get executed. Normally you take an existing class and add something. Please see the tutorials here: http://wiki.oxidforge.org/Tutorials#Modules_and_Extensions. Those tutorials probably won’t be using the new metadata file, but the principles are the same.
With “index.php?cl=x_module” you use your class as current controller. MVC of Oxid: every call loads a class in “views” (in fact the controller in MVC), init method is executed, then render method is executed and returns a template which is then loaded (the view in MVC). This template can also call methods in the controller. All methods get data from the classes in “core” (the model in MVC).
One way to have code executed everywhere is to extend oxviewconfig and call your method from template ($oViewConf->yourMethod()).
thnx vanilla thunder for the tip
@leofonic
that some info you posted there
explains a lot and saved me a bunch of times…
thnx a lot
Sure your module outputs everything without a template, I assumed it was only for testing purposes.
In case you need the functionality of your code on every page a component class is probably the best decision (and a bit easier than a ‘normal’ module).
Go create a new class in Oxid’s view folder, name it mycomp.php and add following content:
<?php
class mycomp extends oxView {
function test() {
echo "test";
}
function _render() {
$this->_oParent->addTplParam('mycomp', $this);
return $this;
}
}
?>
In your config.in.php locate the variable named
$this->aUserComponentNames
and add ‘mycomp’ => 0 to the array
If it’s your only component it should look like
$this->aUserComponentNames = array('mycomp' => 0);
From now on you can access your components functions in your templates like
this:
[{ $mycomp->test() }]
hi jschindler… thnx for the reply… but I don’t think that is what I was searching for, I want to use this module on multiple shops, this would not be best way I think. Still thnx for your support