CodeIgniter Forums
Pagination don't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Pagination don't work (/thread-74851.html)



Pagination don't work - dimonisse - 11-15-2019

Hi all!
I'm trying to configure pagination for my project, I do everything according to the documentation, but I get an error. With version 3, there were no such problems ((

PHP Code:
lass User extends Controller{
    
    
public $model;
    public $locale;

    function __construct()
    {
        $this->locale  =  service('request')->getLocale();
        $this->model = new UserModel();
    

    /*
     * Listing of users
     */
    function index()
    {

        $data = [
            'users'=>$this->model->get_all_users()->paginate(10),
            'pager'=>$this->model->get_all_users()->pager,
            'locale' => $this->locale
        
];

        echo view('admin/header',$data);
        echo view('admin/user/index',$data);
        echo view('admin/footer');
    

Model:
PHP Code:
class UserModel extends Model
{
    protected $db;
    protected $builder;

    function __construct()
    {
        $this->db = \Config\Database::connect();
        $this->builder $this->db->table('users');
    }
  /*
     * Get all users
     */
    function get_all_users()
    {

//        $this->builder->select('id_user, name_user');
        $this->builder->orderBy('id_user''asc');

        return $this->builder->get()->getResultArray();
    
Error:

Quote:Error
Call to a member function paginate() on array search →



RE: Pagination don't work -> problem resolved - dimonisse - 11-15-2019

as it turned out, in the file \system\Model.php, line 442

$ this-> tempReturnType = $ this-> returnType; costs AFTER $ row = $ row-> getResult ($ this-> tempReturnType); I moved it before this expression and it worked.