Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6203371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:54:15+00:00 2026-05-24T04:54:15+00:00

I am still learning to make a Joomla component, but I have run into

  • 0

I am still learning to make a Joomla component, but I have run into a situation which I cannot find the answer to in any tutorial or book I have read so far.
I have a Model (in models/weather.php) which has a method getData(). This method is called from View (in views/view.html.php) and this gets a range of records from my database.
This range of records is then iterated through in my layout (views/tmpl/default.php) using a foreach loop, something like this:

if ($this->item) {
   foreach ($this->item as $item) {
      //...
   }
}

What I need to do is at the point of the comment (//…) I want to retrieve some other record from another table based on the value of $item->id. My question is how do I do this according to best practice? I suppose I could just open up the database right there and get the data I need, but I am suspecting that in a MVC based program I need to put this query in a function or method? Where do I put this and how do I access it? A link to an example would be much appreciated.

ANSWER:
I am such an idiot. Obviously I can just call any method from the view in my layout and in that method I can access my Model (where I can create the lookup function). Sometimes my mind is (still) too procedural to simply ‘see’ OOP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:54:16+00:00Added an answer on May 24, 2026 at 4:54 am

    It is bad practice to process data in the layout(default.php). Layout should only display already retrieved and processed data from model via view(view.html.php). Why don’t you add another method to your model and call that method from getData? It would be much better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still learning socket programming (using Perl) but I have both options (
Ok I am still learning this... I have Googled and done some research but
This might be a silly question but I am still learning. I have read
So I am a relatively new programmer and am still learning, and have run
I still learning Ruby on Rails, but have been wondering what happens if I
Still learning WPF....thanks for any help. Is there any way to Refactor this: <ListBox
Still learning JSP Web Applications here. I have been doing this for a while
I'm still learning the ropes of Git (love it!) but the other day I
I'm still learning Python, and I'd love to know a way to make the
I am new to C# (still learning). My problem statement is that i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.