Welcome Guest, Not a member yet? Register   Sign In
Problems with pagination
#2

(This post was last modified: 04-14-2020, 04:38 AM by wdeda.)

Hi!
You will probably have to use 2 models.
In my case, for example, I have a record where the four main genres are listed, when I click on one of the genres, all the albums I have of that genre are listed.

Model where I collect the DB data:
PHP Code:
<?php namespace App\Models;

// 20200408

use CodeIgniter\Model;


class 
AlbunsDataModel extends Model
{
    
    
protected $table 'albuns';
    protected $allowedFields = ['id''title''ano'];
    protected $returnType 'object';    
    


Model with the research arguments:
PHP Code:
<?php namespace App\Models;

//20200408

use CodeIgniter\Model;

class 
AlbunsListModel extends Model
{
    public function getGenre1()
    {
        $request = \Config\Services::request();
        $uri $request->uri;
        $id $uri->getSegment(3);
        $db db_connect();
        $query $db->table('albuns')
        ->where('id'$id)
        ->get();

        foreach($query->getResult() as $row);
      
        
return $row->style1;
        
    
}

    public function numGenre1()
    {
        $request = \Config\Services::request();
        $uri $request->uri;
        $id $uri->getSegment(3);
        $db db_connect();
        $query $db->table('albuns')
        ->where('id'$id)
        ->get();

        foreach($query->getResult() as $row);
        
        $numgnr1 
$db->table('albuns');
        $numgnr1->where('style1'$row->style1);
        $numgnr1->orderBy('ano''asc');
        $data $numgnr1->countAllResults();
        
        
return $data;
    }
    
    
//and so on... 

Controller:
PHP Code:
<?php namespace App\Controllers;
 
 
//20200410
 
    use CodeIgniter\Controller;
    use App\Models\AlbunsDataModel;
 
  use App\Models\AlbunsListModel;

    class Albumlists extends Controller {    
        
    
public function genre1()
    {        
        $dataModel 
= new AlbunsDataModel();
        $listModel = new AlbunsListModel();

        $style $listModel->getGenre1();
                
        $data 
= [
            'genre1' => $dataModel->orderBy('player_id''ano''title''asc')
            ->where('style1'$style)
            ->paginate(20),
            'pager' => $dataModel->pager,
            'total' => $listModel->numGenre1(),
            'genre' => $listModel->getGenre1()
        ];
        
        $genre 
$listModel->getGenre1();

      $header = array ( 
 
'icon' => 'favicon'
 
'css' => 'albumlists',
 
'title' => $genre' records - wdeda',
 
'search' => '/ci4/search/allmedia/',
 
'placeholder' => 'Pesquisar'
 
);

 echo 
view('templates/header'$header);
 echo 
view('content/albums/genre1'$data); 
 echo 
view('templates/footer');
    }
    
    
//and so on...
    
Reply


Messages In This Thread
Problems with pagination - by SigveR - 04-13-2020, 04:06 PM
RE: Problems with pagination - by wdeda - 04-14-2020, 04:34 AM
RE: Problems with pagination - by Jenny425 - 07-02-2020, 08:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB