Page 1 of 1

Class problem

Posted: Wed Nov 21, 2007 1:50 pm
by Muneo
I am developing a module that print select form. So, I am trying to use JHTMLSelect (in /tmpl/default.php), but the system give the follow error:
Fatal error:  Class 'JHTMLSelect' not found in...

The code is:

Code: Select all

foreach ($weblinks as $link) : 
   echo JHTMLSelect::option($link->url, $link->url);
endforeach;


It's seems that this class (JHTMLSelect) doesn't load correctly...
Can Someone Help me? Thank you...

Re: Class problem

Posted: Wed Nov 21, 2007 3:55 pm
by ircmaxell
Well, you need to load it.  Before the foreach loop, try adding this:

Code: Select all

jimport("joomla.html.html.select");

Re: Class problem

Posted: Wed Nov 21, 2007 4:40 pm
by Muneo
Thank you for your help, but I saw the JHTMLSelect's implementation and the return is object. I thought that this class print the option...

:(

Re: Class problem

Posted: Wed Nov 21, 2007 4:44 pm
by ircmaxell
What you do, is something like this

Code: Select all

foreach ($weblinks as $link) {
$options[] = JHTMLselect::option($link->url, $link->url);
}

$html = JHTMLselect::genericlist($options, "name_to_use");
echo $html;


where name_to_use is the name of the select tag...

Re: Class problem

Posted: Wed Nov 21, 2007 5:58 pm
by Muneo
Simply perfect...
Thanks a lot!!!  :)

Re: Class problem

Posted: Wed Nov 21, 2007 6:02 pm
by ircmaxell
Now, the question is, do you see why that works?

Take a look at /libraries/joomla/html/html/select.php... 

Re: Class problem

Posted: Wed Nov 21, 2007 6:09 pm
by Muneo
Yes!  ;)
Your solution is construct the array with options firstly and after mount the select (that return html code) and print with echo...

My module is using that now... http://muneo.joanopolis.com.br/index.php?option=com_content&view=article&id=49:Weblinks%20Suite%201.0&catid=35:M%C3%B3dulo&Itemid=57

Re: Class problem

Posted: Wed Nov 21, 2007 6:10 pm
by ircmaxell
Glad to hear it!