Welcome Guest, Not a member yet? Register   Sign In
Pagination Problems
#9

That's because if you look at the paginate method it is using findAll() to get the record set.

I use it like above to return my categories by id and it works fine no idea why it's not working
for you.


Model:

PHP Code:
    // -------------------------------------------------------------------

    /**
     * getAllPostsByCategory ()
     * -------------------------------------------------------------------
     *
     * $query = $builder->get(10, 20);
     * $query = $builder->get($limit, $offset);
     *
     * @param  int $categoryID
     * @return PostModel
     */
    
public function getAllPostsByCategory(int $categoryID 0) : PostModel
    
{
    
    $this->categoryID $categoryID;

        
$builder $this->builder();

        
$builder->where("category_id"$categoryID)
        
        ->where('status''published');

        return 
$this;
    } 

Controller:

PHP Code:
    /**
     * -------------------------------------------------------------------
     * category ()
     * -------------------------------------------------------------------
     *
     * @param int $id
     */
    
public function category(int $id 0)
    {
        
$pager Services::pager();

        
$posts      = new PostModel($this->request);
        
$categories = new CategoryModel();

        
$data = [
            
'posts'       => $posts->getAllPostsByCategory($id)->paginate(10'group1'),
            
'pager'       => $posts->pager,
            
'currentPage' => $posts->pager->getCurrentPage('group1'),
            
'totalPages'  => $posts->pager->getPageCount('group1'),
            
'category'    => $categories->getCategory($id),
            
'categories'  => $categories->getTopCategories(),
            
'titles'      => $categories->getCategoryTitles($id),
            
'title'       => 'Blog Categories',
            
'typography'  => Services::typography(),
        ];

        
$data['pageHeading'] = $data['titles']['title'];
        
$data['subHeading']  $data['titles']['sub_title'];

        
// Make all variables global to all views...
        
echo view('Insitefx\Blog\Views\view_data'$data);
        echo 
view('Insitefx\Blog\Views\posts\index');
    } 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Pagination Problems - by Gary - 09-29-2020, 11:36 AM
RE: Pagination Problems - by InsiteFX - 09-29-2020, 03:56 PM
RE: Pagination Problems - by nc03061981 - 09-29-2020, 05:33 PM
RE: Pagination Problems - by InsiteFX - 09-29-2020, 05:36 PM
RE: Pagination Problems - by nc03061981 - 09-29-2020, 05:40 PM
RE: Pagination Problems - by Gary - 09-30-2020, 04:24 AM
RE: Pagination Problems - by nc03061981 - 09-30-2020, 06:13 PM
RE: Pagination Problems - by Gary - 10-01-2020, 04:01 PM
RE: Pagination Problems - by InsiteFX - 10-01-2020, 04:53 PM
RE: Pagination Problems - by nc03061981 - 10-01-2020, 05:40 PM
RE: Pagination Problems - by Gary - 10-02-2020, 02:45 AM
RE: Pagination Problems - by heriniaina - 06-12-2022, 08:44 AM
RE: Pagination Problems - by Gary - 06-23-2022, 09:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB