Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Getting a user name from a user ID
  • I'm a complete beginner to FuelPHP (and the MVC structure in general really) and have just finished following Phil Sturgeon's excellent "Build an admin panel" guide. I decided that I would like to further enhance the comments there though by only allowing comments by registered users. I hence changed a few things - it wasn't really difficult after all. I do have a slight query though. I've currently added the follwoing to the post view to get the comment author's username from their user ID but I'm not sure it's all that efficient: Model_User::find($comment->user)->username I can't see any way to see what SQL queries are being run on a page but I guess doing the above is running at least 1 query. Is there a better way to do this?
    EDIT: Another thing I was wondering about is that HTML seems to be stripped out by default when using the save() method (I'm guessing via htmlentities). Any way to stop this?
  • As to your first question: I'm not familiar with Phil's tutorial, but if he's using the ORM, you can add the related field to the original comment query. If it's Model_Crud, a separate query is needed as that doesn't support relations. FuelPHP encodes on output as a security measure. You can disable encoding on a per-variable basis by setting "false" as third parameter of the set() method of the view object.
  • Harro Verton wrote on Sunday 26th of February 2012:
    As to your first question: I'm not familiar with Phil's tutorial, but if he's using the ORM, you can add the related field to the original comment query. If it's Model_Crud, a separate query is needed as that doesn't support relations. FuelPHP encodes on output as a security measure. You can disable encoding on a per-variable basis by setting "false" as third parameter of the set() method of the view object.

    In response to the first part, I'm doing the following to get the posts and comments: $post = Model_Post::find_by_slug($slug, array('related' => array('user', 'comments'))); I managed to work out how to disable the encoding, though I applied it to the whole $post variable rather than just the content. I know it's less safe this way buy seeing as posts can only be created by trusted users anyway it should be OK. EDIT: I fear I might have made a stupid error. I must have made a spelling mistake while creating my comments model as it was looking for user_i rather than user_id. I just fixed this and everything seems to be working without doing what I was doing above. D'oh!

Howdy, Stranger!

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

In this Discussion