Page 1 of 1

CTLModuleMaker Pull down Menus (Solved)

Posted: Sun Nov 18, 2012 2:29 pm
by andrewvideo
Hi

I am trying to make a module and I use CTLModuleMaker. I need some help. Do anyone know how to change the order the pull down menus in the admin section (Edit item). Now is set alphabetical order by name. I would like to set it to id order. So my menu look cleaner.

I am a little confused what to change. I only know basic PHP :(

I had a look a this page http://www.ctlmm.com/blog/12/Dropdown-f ... betically/

I am still confused, Here is the code I tried changing

Can anyone help.

Code: Select all

$dbresult = $db->Execute("SELECT `$value_field` thelabel, `$value_field` thevalue FROM $tablename ORDER BY `$id_field`");

Re: CTLModuleMaker Pull down Menus

Posted: Sun Nov 18, 2012 2:51 pm
by Jo Morg
It seems you have backticks where there should be just single quotes (IIRC)... so try this:

Code: Select all

$dbresult = $db->Execute("SELECT '$value_field' thelabel, '$value_field' thevalue FROM $tablename ORDER BY '$id_field'");
<edit> on second thought I'm wrong too.... backticks CAN be used but may have compatibility issues with some servers setups... so this should work:

Code: Select all

$dbresult = $db->Execute("SELECT $value_field thelabel, $value_field thevalue FROM $tablename ORDER BY $id_field");

Re: CTLModuleMaker Pull down Menus

Posted: Sun Nov 18, 2012 6:21 pm
by andrewvideo
Sorry I still cant get it to work. is everything else I need to change or missed

Cheers

Code: Select all


	$dbresult = $db->Execute("SELECT $value_field thelabel, $value_field thevalue FROM $tablename ORDER BY $id_field");
		}else{
			$tablename = $this->module->tablename('fieldoptions');
			$dbresult = $db->Execute("SELECT `name` thelabel, `id` thevalue FROM $tablename WHERE field_level_name=? ORDER BY `name`", array($this->level.'_'.$this->name));


Re: CTLModuleMaker Pull down Menus

Posted: Mon Nov 19, 2012 9:11 am
by klenkes
andrewvideo wrote:Sorry I still cant get it to work. is everything else I need to change or missed

Code: Select all


	$dbresult = $db->Execute("SELECT $value_field thelabel, $value_field thevalue FROM $tablename ORDER BY $id_field");
Sorry but you can't just change $label_field to $id_field, because $id most likely is not available.

Available are $label_field and $value_field.
$label_field refers to the field you specified during the module creation for the label of your dropdown.
$value_field would be the value! (who would have guessed...)

So... what is available here depends on what you specified during the creation process of your module's dropdown.

If you specified ($item->)name for the label and ($item->)alias for the value, no ID is now accessible.

You have to specify ($item->)name for the label and ($item->)id for the value. Then you can sort by the id with $value_field.

As an example look at this screenshot:
Image
It produces a select(dropdown) with all content pages sorted by the content_id and the menu_text as label.
If would have taken the content_alias, no sorting by ID would be possible.

Re: CTLModuleMaker Pull down Menus

Posted: Mon Nov 19, 2012 1:47 pm
by andrewvideo
I had a look at that in the in CTLModuleMaker and no luck. :( and not worked. I tried things like content_id, entryname_id, id.


I had the problem fixed in this post awhile back in
http://forum.cmsmadesimple.org/viewtopi ... =7&t=60503 and as someone ask the moderator to removed the post thinking it was edting core files which its not. >:( Unfortunately I can't find a old backup of the module I made awhile back.

Changing php code did fixed it came from the removed post.


Have you got any other suggestions. Your help is well appreciated. Thank you.

Re: CTLModuleMaker Pull down Menus

Posted: Mon Nov 19, 2012 2:26 pm
by andrewvideo
I found the problem and fix it. That code does work. I had other modules made by CTLModuleMaker and they was over riding the classes in the other modules was made.

I think your way would be better if could workout how to it.

Thank your help

For people are looking how to do it. :)

Look for the file class.ctlmm_field.php in the folder /MODULENAME/classes/

Open it and search for the function:
public function getOptionsArray($db=false) and find this line.

Code: Select all

$dbresult = $db->Execute("SELECT $value_field thelabel, $value_field thevalue FROM $tablename ORDER BY $id_field");
Than change it to this.

Code: Select all


$dbresult = $db->Execute("SELECT `$label_field` thelabel, `$value_field` thevalue FROM $tablename ORDER BY `$value_field`");


Re: CTLModuleMaker Pull down Menus

Posted: Mon Nov 19, 2012 2:30 pm
by klenkes
What did you enter in the creation process?
(Like the image in the post above.)

If you entered nothing, then default values are id for values and name for labels.
Then this should work:

Code: Select all

$dbresult = $db->Execute("SELECT `$label_field` thelabel, `$value_field` thevalue FROM $tablename ORDER BY `$value_field`");
Is it still sorted alphabeticaly?

Re: CTLModuleMaker Pull down Menus (Solved)

Posted: Mon Nov 19, 2012 4:43 pm
by andrewvideo
Yes its working just fine now. Its sorting by id. Oh yes. The fields are left blank now.

The problem was it getting the classes that exists in others modules that i made and over riding the class i was editing.

thank you for help

Cheers