Menu

iTop 3 - exec.php

2022-01-14
2022-01-27
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2022-01-14

    I'm trying to modernize some of my extensions by making use of the exec.php page (nice to see it will be possible to include files from subdirectories in the near future!)

    Anyhow, if I a simple file which I then call with a structure like https://127.0.0.1:8182/iTop3/web/pages/exec.php?&exec_module=jb-faq&exec_page=router.php&exec_env=demo-faq , I get some errors.

    I tried each of these PHP instructions one by one in the file; nothing else is in the file.

    echo utils::GetAbsoluteUrlModulesRoot().'/jb-faq';
    

    Works as expected

    echo utils::GetCurrentModuleSetting('test', 3);
    

    throws this error:

    <b>Fatal error</b>:  Uncaught Error: Call to undefined function GetModulesInfo() in C:\xampp64\htdocs\iTop3\web\application\utils.inc.php:2104
    Stack trace:
    #0 C:\xampp64\htdocs\iTop3\web\application\utils.inc.php(2171): utils::GetCurrentModuleName(1)
    #1 C:\xampp64\htdocs\iTop3\web\env-demo-faq\jb-faq\router.php(11): utils::GetCurrentModuleSetting('test', 3)
    #2 C:\xampp64\htdocs\iTop3\web\pages\exec.php(65): require_once('C:\\xampp64\\htdo...')
    #3 {main}
      thrown in <b>C:\xampp64\htdocs\iTop3\web\application\utils.inc.php</b> on line <b>2104</b><br />
    

    So I expected I simply couldn't use things related to "current module".
    So I tried

    echo MetaModel::GetModuleSetting('jb-faq', 'test', 3);
    

    Which now results in

    <br />
    <b>Fatal error</b>:  Uncaught Error: Call to a member function GetModuleSetting() on null in C:\xampp64\htdocs\iTop3\web\core\metamodel.class.php:6727
    Stack trace:
    #0 C:\xampp64\htdocs\iTop3\web\env-demo-faq\jb-faq\router.php(9): MetaModel::GetModuleSetting('jb-faq', 'test', 3)
    #1 C:\xampp64\htdocs\iTop3\web\pages\exec.php(65): require_once('C:\\xampp64\\htdo...')
    #2 {main}
      thrown in <b>C:\xampp64\htdocs\iTop3\web\core\metamodel.class.php</b> on line <b>6727</b><br />
    

    Is this expected?

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2022-01-24

    The line where it goes wrong is
    return self::$m_oConfig->GetModuleSetting($sModule, $sProperty, $defaultvalue);

    Does config need to be initiated somehow first?

    Update: Hipska gave me this answer:
    Only thing that is needed to be added is something like..

    require_once(APPROOT.'application/startup.inc.php');
    
     

    Last edit: Jeffrey Bostoen 2022-01-24
  • Pierre Goiffon

    Pierre Goiffon - 2022-01-27

    Hello Jeffrey,

    Indeed this is not well written in the PHPDoc for this method but \utils::GetCurrentModuleSetting uses \MetaModel::$m_oConfig : this last attribute is initialized on metamodel startup, or manually using \MetaModel::LoadConfig.

    Another way would be to use \utils::GetConfig to get current config (that will work wheter the metamodel is loaded or not), and then call \Config::GetModuleSetting

    But warning : module settings are meant to be overrided in XML, so that you can share it between iTop instances, and deploy modifications using the Designer. See Modules parameters

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.