Welcome, Guest
Username: Password: Remember me

TOPIC: Adding conditional statements

Adding conditional statements 06 Jun 2012 04:22 #2485

  • geoffr
  • geoffr's Avatar
  • Offline
  • Senior Member
  • Posts: 68
  • Thank you received: 2
  • Karma: 0
This is no doubt a no-brainer for many here, but because I am not entirely familiar with Joomla coding, I hope you don't mind me asking...

I'm building a template override for a flysheet (so I don't lose it each time I update the component). This is OK, however, I have a field that I don't want to display in some results. Here is the code that displays the value of a field...

<?php echo JDom::_('html.fly', array(
'dataKey' => 'media_caption',
'dataObject' => $this->questionsitem
));
?>

To precede this with a conditional, I have tried the following, but it errors. Hopefully you can see waht I am trying to do.... Are you able to advise how to write this?

<?php if ( empty( JDom::_('html.fly', array('dataKey' => 'media_caption','dataObject' => $this->questionsitem))) ) { ?>

.... blah blah...

<?php } ?>


Thanks!
Geoff
Last Edit: 06 Jun 2012 04:25 by geoffr.
The administrator has disabled public write access.

Re: Adding conditional statements 06 Jun 2012 05:09 #2486

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Hey Geoff,

(No, I am not the only person active on this forum LOL, it's just that I'm here quite a lot.)

I see you're making excellent progress on understanding Cook Self Service with Joomla!.

Now, this (JDom) is an area that I am not an expert in so please forgive me if this sounds odd.

First, can we have the error being spat out by PHP please?

Next, and this is where I am treading on thin ice, I see you are checking to see if an Object is empty. Perhaps checking to see if JDom is empty is not a good thing (again, i could be wrong!), so maybe you could check to see if the actual value of the object is valid:
if (empty($this->questionsitem)) {
 ... blah ... blah
}

I think you'll see what I mean, but I humbly apologise in advance to those that know better than I if this is way off track. I guess we'll both learn.

Regards,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
Last Edit: 06 Jun 2012 07:13 by edwardcox.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Adding conditional statements 06 Jun 2012 06:54 #2487

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Please edit your message and use the 'code' tag.


Edward is right, it is better to test the value of the object instead of the html returned by JDom.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Adding conditional statements 06 Jun 2012 11:34 #2492

  • geoffr
  • geoffr's Avatar
  • Offline
  • Senior Member
  • Posts: 68
  • Thank you received: 2
  • Karma: 0
Thanks for the replies. I tried testing the object, and doesn't seem to work. I realise the following is incorrect, but if you understand its intent, perhaps you can advise how to properly evaluate it?
if ( !empty( JDom::_('html.fly', array('dataKey' => 'media_caption','dataObject' => $this->questionsitem))) ) {

That is, would you mind confirming the proper syntax for testing the actual field value in the above line,
$this->questionsitem
?

Thanks again,
Geoff
The administrator has disabled public write access.

Re: Adding conditional statements 06 Jun 2012 12:30 #2493

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Hi Geoff,

So, here's what I tried and it works as advertised. The code section will only display the JDom output IF the value of my field '$this->transactionsitem->amount' (where 'amount' is my actual field..) is not empty. Is that what you are trying to accomplish?
<tr>
			<td align="right" class="key">
				<label for="amount">
					<?php echo JText::_( "QUOTEPLEASE_FIELD_AMOUNT" ); ?> :
				</label>
			</td>
			<td>
				<?php if (!empty($this->transactionsitem->amount)) { 
				echo JDom::_('html.form.input.text', array(
												'dataKey' => 'amount',
												'dataObject' => $this->transactionsitem,
												'size' => "10",
												'validatorHandler' => "decimal_10_2",
												'validatorRegex' => "/^\d{0,8}(\.\d{0,2})?$/"
												));
			}	?>
			</td>
		</tr>

Please let us know if that's not what you were trying to accomplish.

Regards,

Edward.

Note to self: contributing to the Forums and helping others is the BEST way to build your own skills and confidence. Just ask me. :-)
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
Last Edit: 06 Jun 2012 12:32 by edwardcox.
The administrator has disabled public write access.

Re: Adding conditional statements 06 Jun 2012 14:09 #2494

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Try this :
echo("<pre>"); print_r($this->transactionsitem); echo("</pre>");

It dump your object, so you can then individually test your object BEFORE to call JDom.
if ($this->transactionsitem->myValue == 'foo')
	...
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Adding conditional statements 08 Jun 2012 03:34 #2507

  • geoffr
  • geoffr's Avatar
  • Offline
  • Senior Member
  • Posts: 68
  • Thank you received: 2
  • Karma: 0
Thanks for the help, but
echo("<pre>"); print_r($this->transactionsitem); echo("</pre>");
didn't return anything (but no error).

I'm really keen to find a solution ASAP ;-)

Thanks,
Geoff
The administrator has disabled public write access.

Re: Adding conditional statements 08 Jun 2012 03:37 #2508

  • geoffr
  • geoffr's Avatar
  • Offline
  • Senior Member
  • Posts: 68
  • Thank you received: 2
  • Karma: 0
Sorry Ed, I can't get this to work. Yes, I am simply trying to test if a field is empty (- or, even better, I am trying to evaluate the value of the field).

many thanks,
Geoff
Last Edit: 08 Jun 2012 03:40 by geoffr.
The administrator has disabled public write access.

Re: Adding conditional statements 08 Jun 2012 04:04 #2510

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Excuse me. If your object is 'questionsitem', then try this :
echo("<pre>"); print_r($this->questionsitem); echo("</pre>");

Please make an effort.
I cannot help you more. What you try to do is really really easy.
You can also try to get help about php searching on google.

www.google.com/search?q=php+test+empty+var
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Adding conditional statements 08 Jun 2012 04:35 #2512

  • geoffr
  • geoffr's Avatar
  • Offline
  • Senior Member
  • Posts: 68
  • Thank you received: 2
  • Karma: 0
Thanks admin, I'm slightly insulted, but I'll get over it ;-) It's not a case of effort, but understanding. I got it working with:
echo("<pre>"); print_r($this->questionsitem->answer_1a); echo("</pre>");

regards.
The administrator has disabled public write access.
Time to create page: 0.077 seconds

Get Started