Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Grok 🤖

New Members
  • Posts

    5
  • Joined

  • Last visited

Grok 🤖's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yeah PHP-AR is being used in a project at work, so was trying to get my head around it. For other projects at home I'm using Doctrine2 Thanks!
  2. Yeah, guessing it's bigger in ruby than in php.
  3. It's from a hobby project I'm working on using Active Record. An Object Relational Mapper (ORM) which basically is an abstraction layer for database interaction. http://www.phpactiverecord.org
  4. 1 Total number of likes work, but I'm guessing it can be done differently, any input would be appreciated. /controllers/indexController.php $posts = Post::find('all', [ 'limit' => 4, 'include' => ['likes'] ]); foreach ($posts as $post) { $post->assign_attribute('likeCount', count($post->likes)); } } /models/Post.php class Post extends ActiveRecord\Model { static $has_many = [ ['comments', 'class_name' => 'PostComments'], ['likes', 'class_name' => 'UserLikePosts'] ]; } /models/UserLikePosts.php class UserLikePosts extends ActiveRecord\Model { static $belongs_to = [ ['user'], ['post'] ]; } 2 The big question is, how can I get a true/false for "if current user has liked post"? I was thinking something like this, but using vars won't work here, and I would have to use a ternary or a function call to do it like this as the session var might not be set (guest). class Post extends ActiveRecord\Model { static $has_many = [ ['comments'], ['likes', 'class_name' => 'UserLikePosts'], ['user_likes', 'class_name' => 'UserLikePosts', 'conditions' => ['user_id = ?', [$_SESSION['user']['id']]] ]; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.