In my custom component, I'm currently stuck with Joomla's way of handling model custom properties. Let's say I have a model Property. To know if this Property is sold, I have to run a query on multiple columns. There's date_sold, but there's also buyer. Both fields have to be checked before being able to say that the Property is sold.

In my view, I can do if ($property->date_sold ... && $property->buyer ...), but is there a way to say if ($property->is_sold)?

I tried in my view.html.php:

$this->is_sold = 0;
if (!is_null($this->property->buyer) && $this->property->date_sold) {
    $this->is_sold = 1;

But this doesn't work. Strangely, var_dump is outputting null, but print_r is outputting 1.

The only way I've found to do this is in the template (default.php). What am I missing?

  • I don't see anything wrong with what you're describing. You may want to check for "I've been staring at this too long" errors... eg: if you're using $this->is_sold in your view.html.php are you using $property->is_sold in your tpl file? Because you should be using $this->is_sold.
    – Drew G
    Mar 30 '17 at 15:26
  • That if clause is handling your date_sold as a boolean. I am assuming you are using a datetime or unix timestamp in your database. Revise your if to handle the clause appropriately and see what happens. Also make sure your buyer field in the database is nullable, or if it is just a null string. Try if != null instead of !is_null. Mar 31 '17 at 14:56


You can modify a Table object (usualy in /administrator/com_yourcomponent/tables/property.php) of this Property to set the is_sold property in load method right after parent::load().


Other way is to modify the model (/components/com_yourcomponent/models/property.php). You modify method getItem() by adding a proper checking code after parent::getItem().


You can also do it in your view.html.php but without a full code its hard to give you a straight answer why what you wrote doesn't work. One tip, if you want to check if item was sold its better to check if date was set like this !empty($this->property->date_sold) or by checking if this is not a zero date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.