New wiki article for creating modules

For newbies who want to create a backend module:

I’ve been looking for a simple tutorial, explaining how to add a custom module to the Oxid backend. After searching in the forum in vain I decided to write an article in the Oxid wiki:

http://wiki.oxidforge.org/Tutorials/Create_a_backend_module_-_1._Getting_started

I don’t have much experience in php, Oxid and the MediaWiki, so I’d be grateful for some feedback or tips from some knowledgable people

I’ll be adding to the wiki article as I get my head around the coding quirks:rolleyes:.

There’s also a thread for German speakers: Wikibeitrag zur Modulentwicklung

Thanks, Timm

few notices:

  1. do not touch /admin/menu.xml !! instead create new one in /modules/modulename/menu.xml with content like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<OX>
    <OXMENU id="NAVIGATION_ESHOPADMIN">
     <MAINMENU id="mxservice">
       <SUBMENU id="bpx_genpics" cl="bpx_genpics" rights="malladmin" />
     </MAINMENU>
    </OXMENU>
</OX>

  1. you must return template name in modulename::render. so the code will look like this:

 <?php
 class bpx_genpics extends oxAdminView
 {
    /**
     * Current class template name.
     * @var string
     */
    protected $_sThisTemplate = 'bpx_genpics.tpl';
   public function render()
   {
     parent::render();
     //
     // put your implementation code here
     //
     //     $this->_aViewData["newVarable"] = 123;
     return $this->_sThisTemplate;
   }
 }

and if you dont have anything to add in render, you can simply skip implementing this method, but remember to define $_sThisTemplate in your class

BTW nice to have tutorial, how to do the module/extensions :slight_smile:

@wanis:
Thanks for the tips!

[QUOTE=wanis;33083]
do not touch /admin/menu.xml !!
[/QUOTE]
I postponed separation of the module from the core files, because I wanted to keep the first steps as simple and painless as possible. I will adress this issue in the next step of the wiki article. BTW I had lots of problems with a separate module folder…

[QUOTE=wanis;33083]
you must return template name in modulename::render.
[/QUOTE]
I’ll put that into the php file in the next step. I reduced the render function to a minimum to get output, and that’s all that was left.

I’ve put the second part of the wiki tutorial online:

http://wiki.oxidforge.org/Tutorials/Create_a_backend_module_-_2._Survive_updates

I’m open for feedback and suggestions for improvement.

Thanks, Timm

This is an applaudable effort. A tutorial like this, especially in English, is long in the waiting!

Thank you regnad!

The third part of the wiki tutorial is done.

http://wiki.oxidforge.org/Tutorials/Create_a_backend_module_-_3._Code_the_module

Hope you enjoy it!

Thanks, Timm

Hi Regard
I want to develop a module for back-end. I have read your articles about creating module but there are some points that I didn’t get from any where.
I know that I should place menu.xml in my folder file containing information about my plugin link on back-end.
Now I want to know the information about my other files my classes, tpl files and my lang file. Where should I place these files. In common practice my classes are placed in admin/ folder, tpl files in out/admin/tpl folder and lang files in out/admin/lang folder. Can I place them in my module folder? If so then what will be the directory structure? Should it be the same as in scattered pattern?
How to place my tpl files, calsses and lang files in my module folder? I have placed all files at the root of my module folder. But I am getting error at main view of admin (“Translation for my module not found”)

You can place your lang files in yourmodulefolder/out/lang/de etc., but i think there is no way to keep all the files inside your modulefolder, especially the templates and classes. You can reference your modulefolder from templates and classes with getModuleUrl from 4.5.0 upwards, don’t know for sure if this also works in backend:

[{oxstyle include=$oViewConf->getModuleUrl('yourmodule',"out/src/css/yourcss.css")}]

to make some use of your module folder, but the main template will still have to be in admin template folder, and your own view classes in the admin folder.

Unfortunately, placing your lang files in module folder will not work in Backend: https://bugs.oxid-esales.com/view.php?id=3399, and getModuleUrl will not work also: https://bugs.oxid-esales.com/view.php?id=3628

Ok. If want to show different screen then how can i do this. For example When i click on my module name on admin navigation it shows a screen. I have shown a form on the first screen. On submission of the form I do some calculation and if calculation goes right then I want to show a different template.
I have tried to do it this way…


if ($result['status'] == 'success')
            {
                $user_id = $result['data']->user_id;
                //enter data in export product table
                $db->Execute("INSERT INTO f_users  (email,user_id ) VALUES ('{$data['email']}','$user_id')");
                
                
                // this is the class which is having different template file. I have called its render function. The control goes to that function but it is not rendered.
                $froomerce_shopcreation = new froomerce_shopcreation();
                $froomerce_shopcreation->render();
                
            }

How can I accomplish this job?

Just return a different template in the render method, like e.g. in admin/newsletter_send.php


    public function render()
    {
        //Send newsletter...

        // end ?
        if ( $blContinue ) {
            return "newsletter_send.tpl";
        } else {
            $this->resetUserCount();
            return "newsletter_done.tpl";
        }
    }

Hi everyone,

i am a newbee, in your article you didn’t mention about the metadata.php file. and now i am on OXID 4.9 version. do i need to create the metadata.php file, because my menu doesn’t shows up when i am placing it in a seperate module. Please help

Hi Bikash (?)
Since writing the turorial I haven’t been working with Oxid anymore, so I can’t help you with the menu system that was introduced after version 4.3. I’m sure other knowledgeable members can give you a tip.

Hi bikashnovalnet,

you definitely have to create a metadata.php file and place in your module root as well as the menu.xml. Then empty the template cache and you should at least see the menu entries.

Greetz
sung_blad