【问题标题】:phpactiverecord - Users::find('all') return empty array - version 0.0.2phpactiverecord - Users::find('all') 返回空数组 - 版本 0.0.2
【发布时间】:2014-01-24 06:16:25
【问题描述】:

我正在使用 codeigniter latestversion,并且我已经安装了 phpactiverecord 版本 0.0.2,

但是当我用这种方法从数据库中检索数据时

$users = Users::find('all') // return nothing

i did       var_dump($users); 

output::
array (size=2)
  0 => 
    object(Users)[39]
      public 'errors' => null
      private 'attributes' (ActiveRecord\Model) => 
        array (size=9)
          'id' => null
          'username' => null
          'email' => null
          'password' => null
          'active' => int 0
          'activation' => null
          'ip' => null
          'created' => null
          'lastaccess' => null
      private '__dirty' (ActiveRecord\Model) => null
      private '__readonly' (ActiveRecord\Model) => boolean false
      private '__relationships' (ActiveRecord\Model) => 
        array (size=0)
          empty
      private '__new_record' (ActiveRecord\Model) => boolean true
  1 => 
    object(Users)[40]
      public 'errors' => null
      private 'attributes' (ActiveRecord\Model) => 
        array (size=9)
          'id' => null
          'username' => null
          'email' => null
          'password' => null
          'active' => int 0
          'activation' => null
          'ip' => null
          'created' => null
          'lastaccess' => null
      private '__dirty' (ActiveRecord\Model) => null
      private '__readonly' (ActiveRecord\Model) => boolean false
      private '__relationships' (ActiveRecord\Model) => 
        array (size=0)
          empty
      private '__new_record' (ActiveRecord\Model) => boolean true

我正在尝试找出问题所在,请帮忙

///// Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends ActiveRecord\Model {

    public function __construct() {
        parent::__construct();
    }

}



/* End of file user.php */
/* Location: ./application/models/user.php */
?>





///// Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends MY_Controller {

    public function __construct() {
        parent::__construct();

    }

    public function index()
    {

        $user = Users::all();

        var_dump($user);

            foreach ($user as $u) {
           echo $u->username.'<br/>';
    }

        ## Rendering the view
        $this->template->view($this->temp, array('page'=>'backend/users'), NULL);
    }

}

/* End of file users.php */
/* Location: ./application/controllers/users.php */


?>




////// Autoload
$autoload['sparks'] = array('php-activerecord/0.0.2');

【问题讨论】:

  • 所以它“什么都不返回”,但是转储变量会得到你所期望的结果吗?那么,您如何确定它什么也不返回呢?
  • 数组为空,它应该包含来自数据库的数据.....即使当我回显 $u->username 时,什么也没有出现
  • 用户名是null,所以什么都不会出现。 (这是一个 PHP 的东西。尽可能逃跑。)似乎问题在于你如何保存记录,而不是读取它们。
  • 我只是获取数据,我没有保存,
  • 我只是不知道为什么它不起作用,我只是决定使用 php-activerecord,我只是在关注文档但没有运气......

标签: php codeigniter phpactiverecord


【解决方案1】:

Users 模型中完全删除__construct() 函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2018-04-30
    • 1970-01-01
    相关资源
    最近更新 更多