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 7704031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:35:38+00:00 2026-05-31T23:35:38+00:00

Normally I would just use URL GET parameters but CodeIgniter doesn’t seem to like

  • 0

Normally I would just use URL GET parameters but CodeIgniter doesn’t seem to like them and none of the URL helper functions are designed for them, so I’m trying to do this the ‘CodeIgniter way’.

I would like to build a page where the model can accept a number of different URI paramters, none necessarily present, and none having to be in any particular order, much like a regular URL query string with get parameters.

Let’s say I have the following url:

http://example.com/site/data/name/joe/

Here not including the controller or the method there would be one parameter:

$params = $this->uri->uri_to_assoc(1);
print_r($params);
// output
array( [name] => [joe] )

If I wanted ‘joe’ to change to ‘ray’ I could do this:

echo anchor('name/ray');

Simple enough but what if there are more parameters and the position of the parameters are changing? Like:

http://example.com/site/data/town/losangeles/name/joe/
http://example.com/site/data/age/21/name/joe/town/seattle

Is there a way to just grab the URL and output it with just the ‘name’ parameter changed?

Edit: As per landons advice I took his script and set it up as a url helper function by creating the file:

application/helpers/MY_url_helper.php

Basically I rewrote the function current_url() to optionally accept an array of parameters that will be substituted into the current URI. If you don’t pass the array the function acts as originally designed:

function current_url($vars = NULL)
{
    $CI =& get_instance();

    if ( ! is_array($vars))
    {
        return $CI->config->site_url($CI->uri->uri_string());
    }
    else
    {
        $start_index = 1;

        $params = $CI->uri->uri_to_assoc($start_index);

        foreach ($vars as $key => $value)
        {
            $params[$key] = $value;
        }

        $new_uri = $CI->uri->assoc_to_uri($params);
        return $CI->config->site_url($new_uri);
    }
}

It works OK. I think the bottom line is I do not like the ‘CodeIgniter Way’ and I will be looking at mixing segment based URL’s with querystrings or another framework altogether.

  • 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-05-31T23:35:39+00:00Added an answer on May 31, 2026 at 11:35 pm

    You can use the assoc_to_uri() method to get it back to URI format:

    <?php
    
    // The segment offset to use for associative data (change me!)
    $start_index = 1;
    
    // Parse URI path into associative array
    $params = $this->uri->uri_to_assoc($start_index);
    
    // Change the value you want (change me!)
    $params['name'] = 'ray';
    
    // Convert back to path format
    $new_uri = $this->uri->assoc_to_uri($params);
    
    // Prepend the leading segments back to the URI
    for ($i=1; $i<$start_index; $i++)
    {
        $new_uri = $this->uri->segment($i).'/'.$new_uri;
    }
    
    // Output anchor
    echo anchor($new_uri);
    

    I’d recommend wrapping this in a helper function of some sort. Happy coding!

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

Sidebar

Related Questions

Normally I would just cheat and use NtQueryInformationThread for ThreadBasicInformation to get the TebBaseAddress
I'm using the skeleton application for ZF2.0.0Beta3. So, normally I would just use Zend_Debug::dump($someVar);
Normally someone would just go and grab Boost's Function Output Iterator but I'm not
Normally I would just do this. $str = preg_replace('#(\d+)#', ' $1 ', $str); If
If I have a table of a hundred users normally I would just set
I would normally use Google analytics because it is free and simple to implement
I'm developing an application that uses Managed WiFi . Normally I would just add
Normally I would just pass an array into a function, however, I am doing
I normally would create a limited rights user and run the process under that
Normally I would go: bgwExportGrid.RunWorkerCompleted += ReportManager.RunWorkerCompleted; The ReportManager class is a static class

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.