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!)
<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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
Works as expected
throws this error:
So I expected I simply couldn't use things related to "current module".
So I tried
Which now results in
Is this expected?
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..
Last edit: Jeffrey Bostoen 2022-01-24
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