Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

template change depending on the value of a field of SOBI2

template change depending on the value of a field of SOBI2

i use this in my rule

$db =& JFactory::getDBO();
$mysobiID =$mySobi->id; // get the sobi2 id NOT WORK ???? alternative $mysobiID ="1" DONT WORK
$myfieldID = "46"; // id type of field predefined value
$query = "SELECT data_txt FROM #__sobi2_fields_data WHERE itemid = $mysobiID AND fieldid = $myfieldID'";
$db->setQuery($query); 
$template = $db->loadResult();

if( $template == 'Green' )
    return "Green";
if ( $template == 'Blue' )
    return "Blue";
if ( $template == 'Orange' )
    return "Orange;

Can not get identification data correctly?

but no work

any idea?

Edited By: Spock
04-Jun-10 18:46:00

Spock
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: template change depending on the value of a field of SOBI2

Hi Spock,

You code looks pretty good, but there are a couple of problems I can see:

1 - your last line will create a PHP error because you missed the final " character.

You need:

    return "Orange";

2 - as you already know, $mySobi will not be populated at this stage of the page loading process. So you need to get the ID value from another source - probably the URL.

You could try:

$mysobiID = JRequest::getVar("sobi2Id");
if ( $mysobiID != "") {
  // ... the rest of your code here...
}

3 - is the name of your template folder definitely "Orange"? Check the actual name of the folder that your template is in. It may be "orange" instead of "Orange". Joomla template names are case sensitive.

4 - to test the template name thing, try using the following rule (just this single line) in MetaTemplate. If this successfully changes the template, then the name is correct :-)

return "Orange";


Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: template change depending on the value of a field of SOBI2

thanks for your answer
one of the failures was due to copy / paste, sorry

Your information is interesting but still does not work
I think not running the data access

does not work if $ mysobiID = "1" actual value of the first record
or if I get by Get parameter

an if i use GET paremater, also will it work with On SEO?
I do not think

so far rejected that feature on my site
until it establishes a rule that I helper.php ensure access to SOBI2 data

thank you very much

sory 4 my english

Spock
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: template change depending on the value of a field of SOBI2

Hi Spock,

I don't know why the data access thing is not working. One thing might be the table prefix... in the recipes above, it's "jos_". However, if your site uses a different prefix, then you'll need to change that. Could that be the reason?

Also, try running this, which might give you some idea of the error that is occurring in the database (if that's what the problem is):

$db =& JFactory::getDBO();
$mysobiID ="1";
$myfieldID = "46"; // id type of field predefined value
$query = "SELECT data_txt FROM #__sobi2_fields_data WHERE itemid = $mysobiID AND fieldid = $myfieldID'";
$db->setQuery($query); 
$template = $db->loadResult();
echo "Template is $template<br>";
echo "database is:<br><pre>" . print_r($db, true) . "</pre>";

This should print out lots of diagnostic info from the database at the top of the page. This will probably completely mess up the formatting of your page, and may even cause page errors depending on your template. But if you're lucky you'll get some diagnostic text.

Regarding SEF URLs: it's a miracle, but the JRequest methods still work with SEF turned on! So my suggestion earlier will definitely still work with SEF turned on.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10778
Newest User:
negina4qx
Members Online:
0
Guests Online:
127

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked