Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. class Article extends Entity
  3. {
  4.     // empty
  5.     // but will auto populated by Table object.
  6.     // there 2 options available to know what attributes that we need to $this->set()
  7.     // 1. Go to the table at database, 2. Go to view template that consumes entity object attributes
  8. }
  9.  
  10. // It's better , because we know what attributes to set IF we change data source
  11. class Article extends Entity
  12. {
  13.     private $title;
  14.     private $viewer;
  15.     private $date;
  16.     private $content;
  17.  
  18.     public function setTitle($title)
  19.     {
  20.         $this->title = $title;
  21.     }
  22.  
  23.     public function setViewer($viewer)
  24.     {
  25.         $this->viewer = $viewer;
  26.     }
  27.  
  28.     public function setDate($date)
  29.     {
  30.         $this->date = $date;
  31.     }
  32.  
  33.     public function setContent($content)
  34.     {
  35.         $this->content = $content;
  36.     }
  37. }
  38.  
  39. $from_redis = $redis->get('somekey');
  40. $data = json_decode($from_redis, true);
  41.  
  42. $article = new Article();
  43. $article->setTitle($data['title_from_redis']);
  44. $article->setViewer($data['viewer_from_redis']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement