Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best way to alter result
  • Hello FuelPHP forum, I was able to succesfully setup the ORM model to use a many_to_many relationship table between "contents" and ""pages". Al I had to do was sticking to the defaults and it worked instantly. Great! My question is, since there are more than one 'contents' for each page, I really want to change the way the ORM structures it's result object. What is the best way to do this? Currently I have to echo my contents like this:
    <address>
    <?=  $page->contents[1]->html;  ?>
    </address>
    

    With this code, I am required to know which content is at index 1. I really want to echo my contents like this:
    <address>
    <?=  $page->contents['contact_info']->html;  // of course the array index here should come from the database column 'name', or something like that ?>
    </address>
    

    The only way I can think of is a looping the contents with a for each, destroying the ORM logic.
  • The number is the 'id' of the record. In a many relation, if you have multiple results, they are all of the same type. So I'm a bit clueless to why you want to access one individual result instead of loop to process them all. If I understand you correctly you have a generic contents table which doesn't contact records of the same type. Then it's logical that you query the contents to see what type it is.
  • Those rows I pulled from contents need to be echo'd on different sections/views on the page. That's why I really wanted them to be logical and human readable like you would do with an associative array. I do not want to alter the results any further, just make them more readable. I guess the only way to hack this is through core, or change the id field to something human readable. Which could work, but I'm not that desperate Thanks

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion