html generator in a static way

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am
Location: Bretagne

html generator in a static way

Post by bess »

for my modules i'd always used to code this :

http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html

Code: Select all

$this->CreateInputPassword(...);
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 ...
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: html generator in a static way

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am
Location: Bretagne

Re: html generator in a static way

Post 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 :

Code: Select all

$this->CreateInputPassword(...);
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 :)
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am
Location: Bretagne

Re: html generator in a static way

Post 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

Code: Select all

function LoadFormMethods()
Replace all call of

Code: Select all

cms_module_create_xxxxx
for

Code: Select all

Html_tools::create_xxxxx
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
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

[The extension txt has been deactivated and can no longer be displayed.]

[The extension txt has been deactivated and can no longer be displayed.]

Last edited by bess on Sat Jun 25, 2011 11:29 pm, edited 3 times in total.
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am
Location: Bretagne

Re: html generator in a static way

Post 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 ;)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: html generator in a static way

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
bess
Language Partners
Language Partners
Posts: 282
Joined: Thu Dec 18, 2008 9:37 am
Location: Bretagne

Re: html generator in a static way

Post 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.
Post Reply

Return to “Developers Discussion”