Keyword

Unable to access item reference in category.php

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 7 months ago #140679 by Michael Yaeger
Unable to access item reference in category.php was created by Michael Yaeger
I am trying to access item data in category.php by:
echo 'Item = '.$this->item->title;
echo $this->item->gallery;

However, I'm only able to access this data after line 124 in my code: www.codeshare.io/fW9ZJ

You can see my attempt to access that data on line 33 and 123. Neither return a value. However, the same code at lines 125 and 376 do.

Why isn't the data accessible?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 7 months ago #140691 by Krikor Boghossian
Replied by Krikor Boghossian on topic Unable to access item reference in category.php
This data is only accessible from within the loop (foreach). You can not access it otherwise.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 7 months ago - 9 years 7 months ago #140759 by Michael Yaeger
Replied by Michael Yaeger on topic Unable to access item reference in category.php
OK, I am able to access the item data by:
foreach($this->secondary as $key => &$item) {}
echo 'Item = '.$item->title;
echo $item->gallery;
Is there a better way to get the item reference without running this empty loop?
Last edit: 9 years 7 months ago by Michael Yaeger.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 7 months ago #140767 by Krikor Boghossian
Replied by Krikor Boghossian on topic Unable to access item reference in category.php
This data should be accessed from that loop.
I would suggest that you look at how the default category/ category_items files work.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
9 years 7 months ago #140773 by Michael Yaeger
Replied by Michael Yaeger on topic Unable to access item reference in category.php
Actually, this data CAN be accessed outside that loop as long as the loop runs first, even if empty.

See lines 33-40 which work:
www.codeshare.io/fW9ZJ#33

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum