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.ph ... &Itemid=57

Re: Class problem

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

Re: Class problem

Posted: Fri May 16, 2008 9:27 am
by kai920
ircmaxell wrote:Well, you need to load it. Before the foreach loop, try adding this:

Code: Select all

jimport("joomla.html.html.select");
Is there any reason why the above jimport statement still gives me a class not found error?

I had to use this instead:

Code: Select all

include_once JPATH_ROOT . "/libraries/joomla/html/html/select.php";

Re: Class problem

Posted: Tue May 20, 2008 1:26 pm
by ianmac
Actually, the correct way to invoke the HTML class functions is for example like this:

Code: Select all

JHTML::_( 'select.option', $link->url, $link->url );
This will take care of importing all the classes you need will handle all loading of files, etc..

Ian