CTLModuleMaker Pull down Menus (Solved)

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

CTLModuleMaker Pull down Menus (Solved)

Post 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`");
Last edited by andrewvideo on Mon Nov 19, 2012 2:27 pm, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1921
Joined: Mon Jan 29, 2007 4:47 pm

Re: CTLModuleMaker Pull down Menus

Post 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");
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: CTLModuleMaker Pull down Menus

Post 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));

klenkes
Power Poster
Power Poster
Posts: 307
Joined: Mon Sep 08, 2008 9:43 am

Re: CTLModuleMaker Pull down Menus

Post 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.
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: CTLModuleMaker Pull down Menus

Post 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.
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: CTLModuleMaker Pull down Menus

Post 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`");

klenkes
Power Poster
Power Poster
Posts: 307
Joined: Mon Sep 08, 2008 9:43 am

Re: CTLModuleMaker Pull down Menus

Post 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?
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: CTLModuleMaker Pull down Menus (Solved)

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

Return to “Modules/Add-Ons”