We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using query parameters and segments

Development and Programming

soapcreative's avatar
soapcreative
9 posts
15 years ago
soapcreative's avatar soapcreative

I’m using uri_protocol “AUTO”. The .htaccess looks like this:

RewriteRule ^(.*) index.php?/$1 [L]

That works! key($_GET) has the entire query string including query parameters. However, the problem comes when I ask for the last segment in a uri that contains query parameters.

Eg:

http://www.example.loc/general/api/contributor_vote/json?vote=2&contributor_id=8

In the module method, I have this code:

$service = $this->EE->uri->segment(3);
$format = $this->EE->uri->segment(4);

Problem I am getting is that $format contains this value:

json&vote=2&contributor_id=8

I really don’t want to do first(explode(‘&’, $this->EE->uri->segment(4))) because that is a hack. I’ve played around with .htaccess and the closest I could get was:

RewriteRule ^([^\?]*)(.*)$ index.php?$1 [L,QSA]

But unfortunately this means that any uri with parameters now makes count($_GET) > 1 and CI decides it cannot use it due to this code:

// codeigniter/system/core/URI.php line 68 (CI_URI::_fetch_uri_string())
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')

I’ve also tried all the other uri_protocols and had various issues with them too. REQUEST_URI would have been the one of choice, but EE_URI::_explode_segments() has a hard-coded rule to reject a uri with a question mark in it.

I’ve been tearing my hair out for two hours now trying to figure out how it is supposed to be done. Can someone tell me if it is possible to use both segments and query parameters without conflict, and what are the correct settings to achieve this?

       
soapcreative's avatar
soapcreative
9 posts
15 years ago
soapcreative's avatar soapcreative

Notice this has been moved from technical support to development and programming. I’m going to hack the core until I can discover whether a configuration exists that behaves as expected. Hmmm, I really did think a defectiveness in the product would have qualified for technical support.. I really hope this doesn’t require a phone call.

       
soapcreative's avatar
soapcreative
9 posts
15 years ago
soapcreative's avatar soapcreative

Ok, here’s my hack:

.htaccess

RewriteRule ^(.*) index.php?$1 [L,QSA]

codeigniter/system/core/URI.php Line 68

if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')

becomes

if (is_array($_GET) && count($_GET) > 0 && trim(key($_GET), '/') != '')

Please can someone tell me if there is a correct way to do this without altering the core.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.