Welcome Guest, Not a member yet? Register   Sign In
How manage the segment error in the URI / pagination class
#1

Good morning all,

I have a question about the segments in the url. I'm currently making a contact list, and I'm using the pagination class.

My url is like this: exemple.fr/contact/all/page/

By default I would like if a user loads the page: example.fr/contact/all/ it is redirected to example.fr/contact/all/1 is this possible? because I have an ArgumentCountError error when loading the page and I don't know how to catch this error.


Thanks
Reply
#2

Can you show some code and some error log? How do you do the redirection? Which function gives you the ArgumentCountError exception?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

Of course, thanks for your reply.

This is my "all" method on my Contact Controller
Code:
    /**
     * list all contacts
     */
    public function all($startLimitResult)
    {
        //Load data from DB
        $data["totalContacts"] = $this->Contact_model->count_all_contacts($profile_id);
        $data["contacts"] = $this->Contact_model->get_page_contacts($profile_id, $startLimitResult, $this->nbsResultPerPage);
           
        //Load Languages files
        $this->lang->load('gml_general', $this->session->userdata('user_lang'));

        //Pagination class
        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'contact/all/';
        $config['page_query_string'] = false;
        $config['use_page_numbers'] = false;
        $config['num_links'] = 2;

        $config['total_rows'] = $data["totalContacts"];
        $config['per_page'] = $this->nbsResultPerPage;
        $this->pagination->initialize($config);

        $this->load->view('head');
        $this->load->view('header');
        $this->load->view('contact/list_contact', $data);
    }

My model
Code:
    //Function to count all contacts
    public function count_all_contacts($userID)
    {
        $this->db->where('profile_id', $userID);
        $this->db->from('contact');
        return $this->db->count_all_results();
    }


    //Function to get all contacts
    public function get_page_contacts($userID, $startLimitResult, $nbsResultPerPage)
    {
        $this->db->where('profile_id', $userID);
        $this->db->from('contact');
        $this->db->limit($nbsResultPerPage, $startLimitResult);
        $query = $this->db->get();
       
        return $query->result();
    }


On page view

Code:
<?php echo $this->pagination->create_links(); ?>

When I select the first link or when I load https://exemple.com/contact/all/ I got this error.


Quote:An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function Contact::all(), 0 passed in /var/www/gml-app/gml_system/core/CodeIgniter.php on line 532 and exactly 1 expected
Filename: /var/www/gml-app/gml_application/controllers/Contact.php
Line Number: 45
Backtrace:
File: /var/www/gml-app/index.php
Line: 327
Function: require_once
Reply
#4

Your function “all” have one parameter. If you go to /contact/all it expect a value for $startLimitResult and it is missing

PHP Code:
public function all($startLimitResult
  

If you want to be able to call this controller with no value, you need to define a default value like this:

PHP Code:
public function all($startLimitResult 0
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

So simple, thanks.
That's exactly what i was looking for, i still lack practice ... i think i may have found a bug. I set previous_link to false but the < still appear...

[Image: Capture-d-e-cran-2020-03-09-a-16-02-37.png]

Code:
       //Pagination class
        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'contact/all/';
        $config['page_query_string'] = false;
        $config['use_page_numbers'] = true;
        $config['num_links'] = 3;
        $config['full_tag_open'] = '';
        $config['full_tag_close'] = '';
        $config['first_link'] = false;
        $config['last_link'] = false;
        $config['previous_link'] = false;
        $config['next_link'] = false;
        $config['cur_tag_open'] = '<li><a href="#"><b style="color:#FFF">';
        $config['cur_tag_close'] = '</b></a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $config['total_rows'] = $data["totalContacts"];
        $config['per_page'] = $this->nbsResultPerPage;
        $this->pagination->initialize($config);
Reply
#6

(03-09-2020, 08:03 AM)nicolas33770 Wrote: i think i may have found a bug. I set previous_link to false but the < still appear...

[Image: Capture-d-e-cran-2020-03-09-a-16-02-37.png]

Code:
$config['previous_link'] = false;

That’s because it’s prev_link, not previous_link!  Big Grin

https://codeigniter.com/user_guide/libra...vious-link
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#7

Wouh My Mistake, sorry, and thanks for your help. It's working Thanks a lot
Reply




Theme © iAndrew 2016 - Forum software by © MyBB