You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2011-05-23 13:38:00

absport
Member
Registered: 2011-05-23
Posts: 3

Problem with class in my new plugin (SOLVED)

hi, im from spain so sorry for my english, i have a problem when developing a new plugin for glpi:

i have a class into glpi/plugins/monitorizacion/inc/plugin_monitorizacion.class.php and it has this code:

class plugin_monitorizacion{
    static function printtree{
           /*and its code*/
    }
}

and a php that calls that class like this:

plugin_monitorizacion::printtree

but the problem is that when i go to the new plugins page, it doesnt work, but if I copy the plugin_monitorizacion.class.php into glpi/inc (that comes with the standard glpi) it works perfect

what should be the problem?

thanks

Last edited by absport (2011-05-24 10:57:22)

Offline

#2 2011-05-23 14:08:20

remi
GLPI-DEV
From: Champagne
Registered: 2007-04-28
Posts: 7,127
Website

Re: Problem with class in my new plugin (SOLVED)

Class, file and table names are standardized

The PluginMonitorizationFoo class must be  stores in plugins/monitorizacion/inc/foo.php.
It it refer to a database table, this table must be glpi_pluginmonitorizationfoos


Dév. Fedora 29 - PHP 5.6/7.0/7.1/7.2/7.3/7.4 - MariaDB 10.3 - GLPI master
Certifié ITILv3 - RPM pour Fedora, RHEL et CentOS sur https://blog.remirepo.net/

Offline

#3 2011-05-23 14:09:23

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: Problem with class in my new plugin (SOLVED)

You must initialize your class
file setup.php
function plugin_init_monitorizacion()
Plugin::registerClass.......

Look at plugin Example


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#4 2011-05-23 16:48:27

absport
Member
Registered: 2011-05-23
Posts: 3

Re: Problem with class in my new plugin (SOLVED)

thank you very much, but it still doesnt work, ill post my code:

setup.php

function plugin_init_monitorizacion() {
   global $PLUGIN_HOOKS,$LANG,$CFG_GLPI;
  Plugin::registerClass('PluginMonitorizacionTree');
   $PLUGIN_HOOKS['newmenu']['monitorizacion']="/plugins/monitorizacion/inc/addmonitorizacion.class.php";
   $PLUGIN_HOOKS['add_javascript']['monitorizacion']="lib/monitorizacion.js";
}

monitorizacion.class.php

<?php
class PluginMonitorizacionTree extends CommonDBTM{
    static function sayhello(){
        echo "<td>hola</td>";
    }
}?>

monitorizacion.form.php

<?php
    ...
    PluginMonitorizacionTree::sayhello(); //this should put "hola" in a table
    ...
?>

Last edited by absport (2011-05-23 17:36:02)

Offline

#5 2011-05-24 09:18:23

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: Problem with class in my new plugin (SOLVED)

Your names are not corrects

You have a class TOTO, the name must be PluginMonitorizacionToto and the file's name must be toto.class.php
This class refere to a database table called glpi_plugin_monitorizacion_totos


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#6 2011-05-24 10:13:25

absport
Member
Registered: 2011-05-23
Posts: 3

Re: Problem with class in my new plugin (SOLVED)

ok, now it works, it was the files name.

Thank you very much! big_smile

Offline

Board footer

Powered by FluxBB