public function index()
 {
     $model = new Model('Comment');
     $count = $model->count();
     $page = new Page($count, 30);
     $list = $model->order('commentId DESC')->limit($page->firstRow . ',' . $page->listRows)->select();
     $this->assign('list', $list);
     $this->assign('page', $page->show());
     $this->display();
 }
Exemplo n.º 2
0
 /**
  * 重写count方法 以支持associate和sqlOptions
  * @param array|string $options count(['hy'=>true]) | count('id')
  */
 public function count($options)
 {
     if (!$this->isCallHyFunc($options)) {
         return parent::count($options);
     }
     return $this->select(array_merge(is_array($options) ? $options : array(), array('count' => true)));
 }
Exemplo n.º 3
0
 public function testMagicMethods()
 {
     $model = new Model('user', $this->getConfig());
     $model->data("first=a&last=z");
     $model->username = '******';
     $data = ['first' => 'a', 'last' => 'z', 'username' => 'test'];
     $this->assertEquals($data, $model->data());
     $this->assertEquals('a', $model->first);
     $this->assertTrue(isset($model->last));
     unset($model->username);
     $this->assertTrue(!isset($model->username));
     $this->assertEquals(2, $model->count());
     $info = $model->getByUsername('test');
     $this->assertEquals(1, $info['id']);
     $id = $model->getFieldByUsername('test', 'id');
     $this->assertEquals(1, $id);
     $id = $model->getFieldByUsername('test', 'id');
     $this->assertEquals(1, $id);
 }