URI Segment with Question Mark - codeigniter

For my Rest WebService I need some variations to put the city or Region or something else in it. So my URI should look like this:
/rest/rating/locations?city=London
Now I'm using following functions to get the last URI Segment:
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
The Problem is here that everthing from the Question Mark gets cutted!
The variable which gets saved is just: locations
I've tried configure following in the config.php:
$config['uri_protocol'] = 'PATH_INFO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';
$config['enable_query_strings'] = TRUE;
Is there any other possibility to save the whole segment with the question mark?

First, make sure you have:
$config['allow_get_array'] = TRUE;
enable_query_strings is actually something else entirely, an old feature that's not used much.
The URI class still won't help you here, you'll have to refer to the query string separately.
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
// Either of these should work
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
$lastseg_with_query = $lastseg.'?'.$query_string;

In your config file, make sure the following is set as TRUE:
$config['allow_get_array']= TRUE;

Related

How to get the full URL of the route?

I have a Sinatra template file, which sends a POST request to the route /en/signup (en is the locale).
I need to extract the en from /en/signup. I tried to use request.path in the following code, but contains only /signup, not /en/signup. The log file shows that /en/signup was called.
What construct can I use in the route post '/signup' in order to get /en/signup?
Wake up, Neo.
From route file:
before '/:locale/*' do
I18n.locale = params[:locale]
request.path_info = '/' + params[:splat ][0]
end
That solved my problem: redirect to('/' + I18n.locale.to_s + '/signup-success').
If you can use java:
var url = document.URL;
var pieces = url.split("/");
Then simply split where and when you need to. The variable pieces is an array. For further splitting use pieces = pieces[1 (or others) ].split("/ (or others ");
I hope this helps!
Hello Sir if you use php try the code below. it will get the full path of the url for instance /example/en/signup.
$_SERVER['REQUEST_URI']
In Addition you can get including the http host (localhost) try the code below
$output = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $output;

routing URI containing email in codeigniter

This is an email activation link written in user controller
http://www.some.com/user/activate_user/user#gmail.com/90101001010
I want to write routes for this.
I tried the below one but its
// USER POST
$route['user'] = 'user';
$route['user/activate_user/:any/:num'] = 'user/activate_user/$1/$2';
Error
An Error Was Encountered
The URI you submitted has disallowed characters.
if i run uri like this it's fine
http://www.some.com/user/activate_user/activate_user/1111/90101001010
why is it not accepting email id?
should be:
$route['user/([\w+-]+)(\.[\w+-]+)*#([a-zA-Z\d-]+\.)+[a-zA-Z]{2,6}/(:any)']
The entire string is a regex without delimiters or modifiers. You were putting delimiters, modifiers and were also using ^ and $.
Please check your config file, which uri chars are you permitted in the url. by default it is look likes:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
if you want further need please visit the link Url Guideline by ellislab
This worked
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_#-';
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2'; –
Go to config.php
Find $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
And add $config['permitted_uri_chars'] = 'a-z 0-9~%.:_()#&\-!';
And the stop and or refresh server
Replace This
$route['user'] = 'user';
$route['user/activate_user/:any/:num'] = 'user/activate_user/$1/$2';
With This
$route['user'] = 'user';
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2';
Added
Tutorial Email Activation
This worked for me
config.php
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_#-';
router.php
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2';

Format Output of Placeholder

I am creating a dynamic list of placeholders, some of the values held in these place holders are decimal numbers that are supposed to represent money.
What I'm wondering is if there is a way I can format them to display as such?
Something like [[+MoneyField:formatmoney]]
I see http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers) but I do not see a way to do this here.
You most definitely can, under the header "Creating a Custom Output Modifier" on the link you posted it's described how you can place a snippet name as a output modifier. This snippet will recieve the [[+MoneyField]] value in a variable called $input.
So you'd have to create this custom snippet which could be as simple as
return '$'.number_format($input);
Another version of doing this is calling the snippet directly instead of as an output modifier like so:
[[your_custom_money_format_snippet ? input=`[[+MoneyField]]`]]
I'm not sure if theres any difference between the two in this case. Obviously you can pass any value into the number format snippet when calling it as a snippet instead of an output modifier. And i'm sure theres a microsecond of performance difference in the two but i'm afraid i don't know which one would win. ;)
Update:
Actually found the exact example you want to implement on this link;
http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-%28output-modifiers%29/custom-output-filter-examples
Snippet:
<?php
$number = floatval($input);
$optionsXpld = #explode('&', $options);
$optionsArray = array();
foreach ($optionsXpld as $xpld) {
$params = #explode('=', $xpld);
array_walk($params, create_function('&$v', '$v = trim($v);'));
if (isset($params[1])) {
$optionsArray[$params[0]] = $params[1];
} else {
$optionsArray[$params[0]] = '';
}
}
$decimals = isset($optionsArray['decimals']) ? $optionsArray['decimals'] : null;
$dec_point = isset($optionsArray['dec_point']) ? $optionsArray['dec_point'] : null;
$thousands_sep = isset($optionsArray['thousands_sep']) ? $optionsArray['thousands_sep'] : null;
$output = number_format($number, $decimals, $dec_point, $thousands_sep);
return $output;
Used as output modifier:
[[+price:numberformat=`&decimals=2&dec_point=,&thousands_sep=.`]]

Append variables to URL after pagination's '/page/x'

I'm using a couple URI variables to handle sorting a table, like this
.../page/7/sortby/serial_number/orderby/desc
as you can see, I'm also using the built in CI pagination library. My problem right now is that the links created with $this->pagination->create_links(); strip off sorting variables from the URI, making it difficult to maintain these sorting options between pages.
How can I go about appending these variables sortby/foo/orderby/bar to the URI of links created by the pagination library?
You can use the base_url option, and the page number segments will have to be last. It's a little annoying, but I think it's the simplest way.
// Get the current url segments
$segments = $this->uri->uri_to_assoc();
// Unset the "page" segment so it's not there twice
$segments['page'] = null;
// Put the uri back together
$uri = $this->uri->assoc_to_uri($segmenmts);
$config['base_url'] = 'controller/method/'.$uri.'/page/';
// other config here
$this->pagination->initialize($config);
I found the answers thanks to WesleyMurch leading me in the right direction. In order to always have the page variable as the last in the uri (which is necessary when using CI's pagination library), I used this
$totalseg = $this->uri->total_segments();
$config['uri_segment'] = $totalseg;
then following WesleyMurch's idea, I rebuilt the base_url,
$segments = $this->uri->uri_to_assoc();
unset($segments['page']); //so page doesn't show up twice
$uri = $this->uri->assoc_to_uri($segments);
$config['base_url'] = site_url()."/controller/method/".$uri."/page/";
and of course initialize the pagination with all the correct config options
$this->pagination->initialize($config);
I use the answer of ejfrancis but...
If for some reason the user put not numeric or negative number in the url's page var, i suggest make a validation before set the $config['uri_segment'], like this one:
$totalseg = $this->uri->segment($totalseg)>0 &&
is_numeric($this->uri->segment($totalseg))?
$totalseg : NULL;
I hope it help!

How do I get the suffix (in code) that is being used for urls?

Magento can add a suffix that is defined by the user to append onto urls. I want to get that suffix from my code. Does anyone know an easy way to do this?
If it's stored in the configuration area, then you access it just as you would any other configuration value, by using Mage::getStoreConfig($config_path) where $config_path is defined in the system.xml of the module that defines it.
If you're not sure of the $config_path, then I usually cheat and inspect the textbox/dropdown in the configuration section, take a look at the id, e.g. dev_log_file, and translate it to dev/log/file. You'll need to use some intelligence when there are multiple _ though :)
Nick's answer is good but the actual answer to this question is:
$suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
If I am not mistaken, here is the code ( because I don't understand what you want with URL )
<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
$url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
echo $url_parts[0]; //check here
?>
complete product url:
$productId = ***;
$productUrl = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();

Resources