Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:40:34+00:00 2026-06-06T20:40:34+00:00

I tried many ways to solve this problem but none works. suppose I have

  • 0

I tried many ways to solve this problem but none works.

suppose I have a class:

class MyTestClass{
    function testPrint($a = '', $b = '', $c = '') 
    {
        echo '1: ' . $a . ', 2: ' . $b . ', 3: ' . $c;        
    }
}

and if I access this function by using this url
http://localhost/ci/index.php/myTestClass/testPrint/a/b/c you will see 1: a, 2: b, 3: c as output, it’s fine.

But if I assign $b to an empty string, the url will change to http://localhost/ci/index.php/myTestClass/testPrint/a//c

The output will change to 1: a, 2: c, 3: It seems CI ignores the missing parameter.

Question is how to prevent CI ignoring the missing parameter in the middle of uri?

My expected output for just now the url is 1: a, 2: , 3: c

Btw, I tried to use $this->uri->segment(n) to secure the parameter position, but it doesn’t work.

I tried to update the routes.php by adding:

$route['myTestClass/(:any)/(:any)/(:any)/(:any)'] = "myTestClass/$1/$2/$3/$4"; but this does not change anything.

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:40:36+00:00Added an answer on June 6, 2026 at 8:40 pm

    I’m not sure if this is possible in your case, but what I would do is use a short dummy string (xyz in this example) just to prevent having to deal with / / and then filtering it out.

    http://localhost/ci/index.php/myTestClass/testPrint/a/xyz/c

    if ($b == 'xyz')
    { 
       $b = ''
    }
    

    If it’s possible, try POST-ing variables instead of using the URI segments. That would make things a lot easier.
    Hope this helps.

    Update:

    Since you can’t POST, how about enabling query strings?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i tried many ways to solve this but missing some thing.. I have
I have tried many ways of executing this but its not happening .. here
I have tried many different ways to solve this that I have found online
I have tried many ways but unable to do this. I have set the
I tried to solve the problem in many ways but without success and I
Sorry if this is really easy. But I have tried many ways to add
I have tried many ways of Asynchronously loading images and they ALL have this
I have tried many ways implementing the below example, but I could not make
Is this correct way? I have tried many ways, it seems that does not
I have tried many ways to achieve this biut unable to delete row from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.