Class problem

Muneo
Joomla! Explorer
Joomla! Explorer
Posts: 491
Joined: Fri Aug 19, 2005 3:02 am
Location: Brazil
Contact:

Class problem

Postby Muneo » Wed Nov 21, 2007 1:50 pm

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

User avatar
ircmaxell
Joomla! Ace
Joomla! Ace
Posts: 1926
Joined: Thu Nov 10, 2005 3:10 am
Location: New Jersey, USA
Contact:

Re: Class problem

Postby ircmaxell » Wed Nov 21, 2007 3:55 pm

Well, you need to load it.  Before the foreach loop, try adding this:

Code: Select all

jimport("joomla.html.html.select");
Anthony Ferrara - Core Team - Development Coordinator - Bug Squad - JSST

http://moovum.com/ - The Bird is in the air! Get Mollom Anti-Spam on your Joomla! website with Moovur...
http://www.joomlaperformance.com For All Your Joomla Performance Needs

Muneo
Joomla! Explorer
Joomla! Explorer
Posts: 491
Joined: Fri Aug 19, 2005 3:02 am
Location: Brazil
Contact:

Re: Class problem

Postby Muneo » Wed Nov 21, 2007 4:40 pm

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

:(

User avatar
ircmaxell
Joomla! Ace
Joomla! Ace
Posts: 1926
Joined: Thu Nov 10, 2005 3:10 am
Location: New Jersey, USA
Contact:

Re: Class problem

Postby ircmaxell » Wed Nov 21, 2007 4:44 pm

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...
Anthony Ferrara - Core Team - Development Coordinator - Bug Squad - JSST

http://moovum.com/ - The Bird is in the air! Get Mollom Anti-Spam on your Joomla! website with Moovur...
http://www.joomlaperformance.com For All Your Joomla Performance Needs

Muneo
Joomla! Explorer
Joomla! Explorer
Posts: 491
Joined: Fri Aug 19, 2005 3:02 am
Location: Brazil
Contact:

Re: Class problem

Postby Muneo » Wed Nov 21, 2007 5:58 pm

Simply perfect...
Thanks a lot!!!  :)

User avatar
ircmaxell
Joomla! Ace
Joomla! Ace
Posts: 1926
Joined: Thu Nov 10, 2005 3:10 am
Location: New Jersey, USA
Contact:

Re: Class problem

Postby ircmaxell » Wed Nov 21, 2007 6:02 pm

Now, the question is, do you see why that works?

Take a look at /libraries/joomla/html/html/select.php... 
Anthony Ferrara - Core Team - Development Coordinator - Bug Squad - JSST

http://moovum.com/ - The Bird is in the air! Get Mollom Anti-Spam on your Joomla! website with Moovur...
http://www.joomlaperformance.com For All Your Joomla Performance Needs

Muneo
Joomla! Explorer
Joomla! Explorer
Posts: 491
Joined: Fri Aug 19, 2005 3:02 am
Location: Brazil
Contact:

Re: Class problem

Postby Muneo » Wed Nov 21, 2007 6:09 pm

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
Last edited by Muneo on Wed Nov 21, 2007 8:47 pm, edited 1 time in total.

User avatar
ircmaxell
Joomla! Ace
Joomla! Ace
Posts: 1926
Joined: Thu Nov 10, 2005 3:10 am
Location: New Jersey, USA
Contact:

Re: Class problem

Postby ircmaxell » Wed Nov 21, 2007 6:10 pm

Glad to hear it!
Anthony Ferrara - Core Team - Development Coordinator - Bug Squad - JSST

http://moovum.com/ - The Bird is in the air! Get Mollom Anti-Spam on your Joomla! website with Moovur...
http://www.joomlaperformance.com For All Your Joomla Performance Needs

User avatar
kai920
Joomla! Guru
Joomla! Guru
Posts: 542
Joined: Sun Sep 04, 2005 3:59 pm
Location: Hong Kong

Re: Class problem

Postby kai920 » Fri May 16, 2008 9:27 am

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";

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4785
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Class problem

Postby ianmac » Tue May 20, 2008 1:26 pm

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


Return to “Joombie Think Tank”

Who is online

Users browsing this forum: No registered users and 2 guests