Page 1 of 1
html generator in a static way
Posted: Sat Jun 25, 2011 3:52 pm
by bess
for my modules i'd always used to code this :
http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html
in classes which extend cms Module class or
Code: Select all
$mod = new CMSModule();
$mod = $mod ->GetModuleInstance('someModule'); (?? not sure)
$mod->CreateInputPassword(...);
in other classes (like toolbox)
but $this & $mod are CMSModule classes so they are very weighty ...
for my next module,i would like to use this code without loading the entire CMSModule class... i only need the html's generator tools ...
have you a solution ? like static classes
someClass::CreateInputPassword(...)
it would cost less memory ...
Re: html generator in a static way
Posted: Sat Jun 25, 2011 4:17 pm
by calguy1000
In principle I agree with you about the form api... we've discussed numerous times re-writing it to be a bit more flexible. However, we don't want to break all existing modules, especially in a large way. So that leaves us with either incremental improvements, or maintaining 2 systems... usually we vote for incremental improvements.
As far as the module objects themselves:
a: They're already loaded (especially in versions up to 1.9.4.2) so there's no need to create a new object.
$mod = cms_utils::get_module('CMSMailer'); is generally good enough to get a module instance just to use the form api.
b: The modules themselves are usually light weight (I've compared the memory usage before and after instantiating the module)... the scripts themselves are the heavy part, and like I said they're already included.
Re: html generator in a static way
Posted: Sat Jun 25, 2011 5:05 pm
by bess
thank you for the answer.
i understand the problem about backwards compatibility.
maybe an idea :
before :
Code: Select all
function LoadFormMethods()
{
if (!$this->modform)
{
require_once(cms_join_path(dirname(__FILE__), 'module_support', 'modform.inc.php'));
$this->modform = true;
}
}
function CreateInputText($id, $name, $value='', $size='10', $maxlength='255', $addttext='')
{
$this->LoadFormMethods();
return cms_module_CreateInputText($this, $id, $name, $value, $size, $maxlength, $addttext);
}
could be
Code: Select all
function LoadFormMethods()
{
if (empty($this->modform))
{
require_once(cms_join_path(dirname(__FILE__), 'module_support', 'modform.inc.php'));
$this->modform = Modform::getInstance(); //static access
}
}
function CreateInputText($id, $name, $value='', $size='10', $maxlength='255', $addttext='')
{
$this->LoadFormMethods();
return $this->modform->cms_module_CreateInputText($this, $id, $name, $value, $size, $maxlength, $addttext);
}
and transforming modform.inc.php into a new static class : Modform
so my code could be :
in classes which extend cms Module class or
Code: Select all
require_once(cms_join_path(dirname(__FILE__), 'module_support', 'modform.inc.php'));
$html_tools = Modform::getInstance();
$mod->CreateInputPassword(...);
in other classes (like toolbox)
obviously i'm not sure ... all code is assumed
I think I'll test at home by converting the file into a static class and see if some lines of code can't be used in static.
I will give news of my tests

Re: html generator in a static way
Posted: Sat Jun 25, 2011 6:10 pm
by bess
2 files :
class.html_tools.txt
new static class. the parameter &$modinstance is not always necessary . Could be better coded... but it's working
class.module.inc.txt
new version with lot of static stuff.
Delete fonction
Replace all call of
for
no problem spotted.
and of course... the new code in my action.default.php file :
Code: Select all
echo Html_tools::CreateFormStart($this, $id, 'do_research', $returnid);
echo Html_tools::CreateInputHidden($this, $id,'search', $searchId);
echo Html_tools::CreateInputSubmit($this, $id, 'submit', $this->Lang('research'));
echo Html_tools::CreateFormEnd();
of course it's not perfect.
some functions don't need the parameter &$modinstance but we need this one for
Code: Select all
$modinstance->get_pretty_url($modinstance, $id,$action,$returnid,$params,$inline);
in create_url()
we also have :
$modinstance->GetName() in createFormStart() & create_url()
$modinstance->cms->config['query_var'] in createFormStart()
we can passing them into new parameter (in an array ?)
but i still don't know how use "get_pretty_url" into a pure static context without make a call to my module instance
hoping that you can make something good on your side
Re: html generator in a static way
Posted: Sat Jun 25, 2011 6:23 pm
by bess
i don't think that making a form in a purely static classe has any sense...
a form is always for a module... so finaly i don't think it could be a problem.
after a small review of the placement of parameters into the new static class (to have better signature) we could maybe use this for cmsms
IMHO

Re: html generator in a static way
Posted: Sat Jun 25, 2011 7:44 pm
by calguy1000
I'll try to keep track of this post... but unfortunately the TODO list for 1.10 is already full (and we're struggling like hell to find time to cross things off).. so this prolly won't happen in CMSMS for 1.10.
Re: html generator in a static way
Posted: Sat Jun 25, 2011 11:05 pm
by bess
no problem.
hope my code will be reuse, i would be glad to help dev team
edit : modified some stuff in my posts.