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 6082627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:18:38+00:00 2026-05-23T11:18:38+00:00

I have an object in a controller’s method: $post = ORM::factory(‘post’, array(‘slug’ => $slug);

  • 0

I have an object in a controller’s method:

$post = ORM::factory('post', array('slug' => $slug);  

that is sent to the view:

$this->template->content = View::factory('view')->bind('post', $post);

I’ve created 1-n relation between post and comments. So good so far.

The main issue is: how should I pass post comments to the view? Currently I’m getting them in the view ($post->comments->find_all()) but I don’t feel it’s the best method (and not matching MVC standards in my humble opinion). I was also thinking about assigning them to the property in the controller ($post->comments) however I get an error about undefined property (which makes sense to me).

How would you recommend to solve that issue?

  • 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-23T11:18:39+00:00Added an answer on May 23, 2026 at 11:18 am

    Why not grab the comments in the controller and pass them to the view for presentation? At least that’s how I’d go about this.

    $post = ORM::factory('post', array('slug' => $slug));
    $comments = $post->comments->find_all();
    $this->template->content = View::factory('view')->bind('comments', $comments);
    

    In regards to your multiple pages comment, which I assume you mean posts…
    This is what I would usually do.

    $posts = ORM::factory('post', array('slug' => $slug))->find_all();
    $view = new View('view');
    foreach ($posts as $post) {
        $view->comments = $post->comments;
        $this->template->content .= $view->render();
    }
    

    Though this may not be the most resource friendly way to accomplish this, especially if you’re working with many posts. So passing the posts to the view and then doing the foreach loop inside the view may be a better way to go about this.

    $posts = ORM::factory('post', array('slug' => $slug))->find_all();
    $this->template->content = View::factory('view')->bind('posts', $posts);
    

    Though I also don’t necessarily think running a select query from the view is the worst thing in the world. Though I’m no expert… 😉

    I had asked this question a while ago in regards to CodeIgniter… passing an Array to the view and looping through it seemed to be the favored response…

    Using CodeIgniter is it bad practice to load a view in a loop

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

Sidebar

Related Questions

I have a controller method that returns a jSON object and in one calling
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding
I have an object that I am developing a controller for that has many
I have an object elem that I'd like to pass to the remove_tag_from_cart method.
I have a bunch of outlets in a controller object that another controller needs
I have an object that contains all login data, that's in my controller (it
I have a object called category, in my view/store/manage.html.erb, I want to do this
I have a controller object implemented as a singleton, which has a cache that
I have an object that has a to_csv method and I want to pass
I have a controller insert action: <AcceptVerbs(HttpVerbs.Post)> _ Function InsertObject(<Bind(Exclude:=Id)> <ModelBinder(GetType(CustomModelBinder))> ByVal object As

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.