Page 2 of 2
Re: Don't use the internals CMSMS in your code.
Posted: Mon Oct 11, 2010 3:10 pm
by Jeff
bess wrote:
in class Foo
Which is better?
Code: Select all
$this->GetPreference("fooPref");
$this->SetPreference("fooPref", 'new value');
or
Code: Select all
cms_utils::get_app_data('fooPref');
cms_utils::set_app_data('fooPref','new value');
These do two different things. The first saves a preference variable in the db. The second save a variable for the page load only.
For variables used during page load/execution the best way is to add it to the module object:
Code: Select all
$this->fooPref = 'new value';
echo $this->fooPref
Which is better?
Code: Select all
$feu = &$gCms->modules["FrontEndUsers"]['object'];
or (i suppose :p)
Code: Select all
$feu = cms_utils::get_module('FrontEndUsers','1.10');
and for
do we must done something ?
Best (IIRC works in 1.8 as well)
$feu = cmsms()->GetModuleInstance('FrontEndUsers','1.10');
$db = cmsms()->GetDb();
$smarty = cmsms()->GetSmarty()
Re: Don't use the internals CMSMS in your code.
Posted: Mon Oct 11, 2010 3:44 pm
by calguy1000
Code: Select all
$feu = cmsms()->GetModuleInstance('FrontEndUsers','1.10');
ajprog is correct except that the GetModuleInstance call is new in CMSMS 1.9
The second (optional) parameter allows you to specify a minimum version number.
Re: Don't use the internals CMSMS in your code.
Posted: Mon Oct 11, 2010 5:48 pm
by bess
if I want to keep backwards compatibility I should do this
Code: Select all
if(function_exists(cmsms) && cmsms() != null)
{
$feu = cmsms()->GetModuleInstance('FrontEndUsers','1.10');
$db = cmsms()->GetDb();
$smarty = cmsms()->GetSmarty();
}
else
{
$feu = &$gCms->modules["FrontEndUsers"]['object'];
$db = &$gCms->GetDb();
$smarty = &$gCms->getSmarty();
}
Am I right?
Re: Don't use the internals CMSMS in your code.
Posted: Mon Oct 11, 2010 6:29 pm
by NaN
Function cmsms() is already in CMSms 1.8.2
Re: Don't use the internals CMSMS in your code.
Posted: Wed Oct 13, 2010 9:13 am
by NaN
One question about the $gCms stuff again.
Most module actions starts with
If $gCms is deprecated what would be the replacement for that?
Re: Don't use the internals CMSMS in your code.
Posted: Wed Oct 13, 2010 6:00 pm
by Duketown
Two questions.
1.
NaN wrote:
Function cmsms() is already in CMSms 1.8.2
Please
confirm note the following: cmsms() was
not available in version 1.8.1 and earlier versions available as of version 1.8.
So if I prepare a new module (or change an existing module to be ready for the next CMSMS version), I need to make sure that the minimum CMSMS version that the module can run in is set to 1.8
.2.
I've always seen the News module as a base if I needed a specific piece of coding (some sort of a reference module since all types of functions are available). If I however look in the SVN version at this moment (Revision 188) it tells me that News.module.php is not using this new setting yet (it contains the 'global $gCms;' line).
Is there another module that I/we should take as an example module?
----------------
2.
Should the phrase that is often around when front end coding is in place:
Code: Select all
$manager =& $gCms->GetHierarchyManager();
be rewritten to:
Code: Select all
$manager = cmsms()->GetHierarchyManager();
?
Thanks,
Duketown
Re: Don't use the internals CMSMS in your code.
Posted: Wed Oct 13, 2010 8:33 pm
by Peciura
Function cmsms() was defined on CMSms 1.8 .
$manager = cmsms()->GetHierarchyManager();
This will be ok. Check any CGExtensions based module released on 2010-10-06 (
Company Directory, CGCalendar)
One question about the $gCms stuff again.
Most module actions starts with
What about this question ?
If $gCms is deprecated what would be the replacement for that?
Re: Don't use the internals CMSMS in your code.
Posted: Wed Oct 13, 2010 9:11 pm
by Duketown
Can I draw a conclusion that if I'm going to upgrade my modules or create a new one, that in all situations I can change:
... & $gCMS->...
into:
... cmsms()->...
Duketown
Re: Don't use the internals CMSMS in your code.
Posted: Wed Oct 13, 2010 9:54 pm
by calguy1000
As a habit, when releasing a module I try to always set the MinimumCMSVersion to the latest supported version which is now 1.8.1. This solves lots of problems, so therefore using the cmsms() function should be safe from 1.8.1 forwards. I checked this once, but I could check again.
As far as to what to put in the top of each action file, this should work:
Code: Select all
$gCms = cmsms(); if( !is_object($gCms) ) exit;
Then there may be only one line to change in each of your action files.