As this will be gone in the next iteration of CMSM 1.9 - see quote below - is there a generic replacement or is the global nature the whole argument? I'm not sure how to prep my site for this and switch over the variables that rely on it . . .
"15) Removed the $gCms variable from smarty.
This has been a contentious issue, but it was decided that for security reasons this variable should not be exported to smarty. This may break some sites that are using some of the internal CMSMS variables to do some things directly in smarty." from: http://forum.cmsmadesimple.org/index.ph ... 209.0.html
[Solved] Global Variable $gCms replacement
[Solved] Global Variable $gCms replacement
Last edited by jaslorax on Fri Apr 15, 2011 5:35 pm, edited 1 time in total.
GoodLuckSigned
jaslorax
jaslorax
Re: Global Variable $gCms replacement
You will not be able to access members of $gCms directly. But you can do everything in UDT.
Similar discussion is here http://forum.cmsmadesimple.org/index.ph ... 403.0.html
There will be even easier ways to access smarty and some commonly used system and custom variables.$gCms = cmsms();
//or even better (but not the best)
$smarty = cmsms()->GetSmarty();
Similar discussion is here http://forum.cmsmadesimple.org/index.ph ... 403.0.html
Re: Global Variable $gCms replacement
Sorry if I am a little daft about this but just to clarify everywhere I have used (in my UDTs):
But this is something I can do now and it will work and if I didn't my understanding is that though it will be deprecated it won't be removed right?
Here is a simply example of my usage for grabbing the query string in a uri:
udt name: current_qs
it simply needs to change to:global $gCms;
$smarty = &$gCms->GetSmarty();
All this does is allow the UDT to be a global variable right? I don't think I fully understand the $gCms and what it does . . . haven't located a great explanation.$gCms = cmsms(); //global $gCms;
$smarty = &$gCms->GetSmarty();
But this is something I can do now and it will work and if I didn't my understanding is that though it will be deprecated it won't be removed right?
Here is a simply example of my usage for grabbing the query string in a uri:
udt name: current_qs
so I'd change to:global $gCms;
$smarty = &$gCms->GetSmarty();
if($_SERVER["QUERY_STRING"]) {
$the_qs = '?'.$_SERVER["QUERY_STRING"];
}
else {
$the_qs ='';
}
$smarty->assign('the_qs', $the_qs);
What was the issue with the old method?$gCms = cmsms(); //global $gCms;
$smarty = &$gCms->GetSmarty();
if($_SERVER["QUERY_STRING"]) {
$the_qs = '?'.$_SERVER["QUERY_STRING"];
}
else {
$the_qs ='';
}
$smarty->assign('the_qs', $the_qs);
GoodLuckSigned
jaslorax
jaslorax
Re: Global Variable $gCms replacement
A the moment that is the best you can do.
"public global" $gCms was just another way to reduce stability of CMSms. It can be used the way it was not meant to thus affecting all system.
It might be removed some time in a future without warning.But this is something I can do now and it will work and if I didn't my understanding is that though it will be deprecated it won't be removed right?
"public global" $gCms was just another way to reduce stability of CMSms. It can be used the way it was not meant to thus affecting all system.
Re: Global Variable $gCms replacement
By the way, this one:
It is removed from smarty means it is removed from smarty. Not from the code at all.
That means you cannot use it in templates anymore.
You won't be able to use
in a template since the var is just not available in a template anymore.
Or this one in a UDT:
won't work anymore.
But this is nothing really critical because if anyone really did use the template var gCms it will be his own fault. This code will have to fail someday.
Just consider the following: Smarty contains a reference of the gCms object and the gCms object contains a reference to smarty. Both were public. So you could do this: $smarty->_tpl_vars['gCms']->smarty->_tpl_vars['gCms']->smarty-> ...
So the code line
has to be removed from the include.php since it is no good design to have a public reference inside an object that contians a public reference to the other object ... (just try to use the smarty plugin {debug}; whenever it comes to the $gCms object it will crash because of endless recursion)
Thats all.
The "public global $gCms" stuff is something completely different. Even if it has also to with design. As you can see it is neccessary to make certain methods, vars or members of an object private to make sure nothing weird happens.
And this will be all that is gonna happen.
If there really is need to access private data of the CMSms internals there will be a public method to get these.
Additionally you won't be able to SET those data anymore.
Again, only if there is really any need to do so, there will be a public method that allows you to set something.
You won't have any trouble with your code if you switch from
to
in all your code now since this function is already available in CMSms 1.8.2.
What exactly is going on inside the cmsms() function or what $gCms actually is, is completely irrelevant to you. Main thing is that it returns something that provides (hopefully well documented) public functions to you to access certain core functions. Thats all you need to know about the $gCms stuff.
has nothing to do with what you're talking about.jaslorax wrote:
"15) Removed the $gCms variable from smarty.
It is removed from smarty means it is removed from smarty. Not from the code at all.
That means you cannot use it in templates anymore.
You won't be able to use
Code: Select all
{$gCms-> ...}
Or this one in a UDT:
Code: Select all
$smarty->_tpl_vars['gCms'];
But this is nothing really critical because if anyone really did use the template var gCms it will be his own fault. This code will have to fail someday.
Just consider the following: Smarty contains a reference of the gCms object and the gCms object contains a reference to smarty. Both were public. So you could do this: $smarty->_tpl_vars['gCms']->smarty->_tpl_vars['gCms']->smarty-> ...

So the code line
Code: Select all
$smarty->assign_by_ref('gCms', $gCms);
Thats all.
The "public global $gCms" stuff is something completely different. Even if it has also to with design. As you can see it is neccessary to make certain methods, vars or members of an object private to make sure nothing weird happens.
And this will be all that is gonna happen.
If there really is need to access private data of the CMSms internals there will be a public method to get these.
Additionally you won't be able to SET those data anymore.
Again, only if there is really any need to do so, there will be a public method that allows you to set something.
You won't have any trouble with your code if you switch from
Code: Select all
global $gCms
Code: Select all
$gCms = cmsms();
What exactly is going on inside the cmsms() function or what $gCms actually is, is completely irrelevant to you. Main thing is that it returns something that provides (hopefully well documented) public functions to you to access certain core functions. Thats all you need to know about the $gCms stuff.
Last edited by NaN on Wed Oct 06, 2010 5:57 pm, edited 1 time in total.