What is uri segment in codeigniter for specific condition? - codeigniter

My url is http://example.come/search?s=code/100
I am using codeigniter for my application.
echo $this->uri->segment(1); Result is 'search';
but what is uri segment for 100?

I think the way you've created the url is incorrect. The query string should be at the end... ie. http://example.come/search/100?s=code. Then the following should work:
echo $this->uri->segment(2);

Related

what is question mark means in the url in php codeigniter framework

i'm beginner in php so i want to ask this question
I read about url in Codeigniter and know url is include controller name and then method name but i didn't know what's question mark means yet ?
for example
where form post data if the url after click on submit button is
http://localhost/code/forums/topic/25674318?addpost=Publish
i'm using Codigniter may i use this url to post submitted data to model i mean insert that data to database.
This is the symbol ? which starts the begining of query in url. And after that you can use & symbol
<?php echo $this->input->get('addpost');?>
http://www.codeigniter.com/user_guide/libraries/input.html?highlight=get
Or
<?php echo $_GET['addpost'];?>
http://php.net/manual/en/reserved.variables.get.php
And then should return Publish
The fist query in url good to have ? then any other query you can use &
Example: http://www.demo.com/example/?token=123456&something=test
$var1 = 123456;
$var2 = 'test';
site_url('example/'. '?token=' . $var1 . '&somthing=' . $var2);
Config
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&=?';

Laravel - Get route by a route name

route('products.create') returns full path like http://myapp.dev/products/create.
How do I get the actual route? Only this -> products/create?
There is no such functionality provided by Laravel at this point. However, you may try this:
$extra = URL::to('/');
$actual = route('products.create');
str_replace($extra, '', $actual);
That will remove the unnecessary base URL from your route URL.

$this->getRequest()->getParam() not working in category controller

I am working on retriving the manufacturer attribute from url
localhost/magento/index.php/test-pro.html?manufacturer/4
So i used $this->getRequest()->getParam('manufacturer')
I did not get any output.
But when i changed the url as localhost/magento/index.php/test-pro.html?manufacturer=4
(/ replaced by =), i get proper output.
But i need the url should be localhost/magento/index.php/test-pro.html?manufacturer/4
and want to fetch the product related to that manufacturer id 4.
Somebody help me.
In your query string ?manufacturer=4 will give you the value for manufacturer i.e. 4, while manufacturer/4 will give you no value as its not being treated as query string.
Also the param will be and the param will be manufacturer/4 and not manufacturer.
To achieve what you require, you can do sometinhg like below.
$currentUrl = 'localhost/magento/index.php/test-pro.html?manufacturer/4';
$parts = parse_url($currentUrl);
$val = explode('/',$parts['query']);
Mage::register('manufacturer',$val[1]);
$menuVal = Mage::registry('manufacturer');
echo $menuVal; //prints 4
This is a sample code by which you can get the query string value even if you use / instead of =.

Magento getProductUrl() is not returning the right url (random?)

I am using Magento 1.5.0.1 and the getProductUrl() function used in the cross sell and up sell blocks on the product page is throwing up different URL formats.
Either the correct url like:
/laptop-bag.html
Or the wrong one (well it works, but of course its not the rewrite URL):
/catalog/product/view/id/825/s/laptop-bag/category/16/
Sometimes both cross sell and up sell blocks return the correct URL, sometimes both use the longer version, and in some cases, one uses the correct and the other uses the long version??
Any ideas why this is happening?
I have already run a magento database repair, reindexed, and refreshes / flushed all caches.
Try $product->getUrlPath() instead of $product->getProductUrl()
UPDATE: As per below comment by #jordan314, Magento recommends to EE customers:
The url_path attribute is no longer used as of 1.13 but is still available for backward-compatibility, and Magento will not assign a value to it for new products, so it's not recommended to continue using it. Perhaps you could try using $product->getProductUrl() instead.
The incorrect url is generated because it can't find the rewritten url.
Maybe it is caused because incorrect store_id.
eg:
$id = 290;
Mage::app()->setCurrentStore('default');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
//change store id
Mage::app()->setCurrentStore('admin');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
result:
store_id: 1
http://local.com/surestep-pro-diabetic-test-strips-50-strips-professional-care.html
store_id: 0
https://local.com/index.php/catalog/product/view/id/290/s/surestep-pro-diabetic-test-strips-50-strips-professional-care/
The correct url rewrite can be found in table named core_url_rewrite (including the information about the store_id)
If it found match value in core_url_rewrite, it will generate 'the correct url' else it will concat the product_id + url key + category_id
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
Try add this when you're getting your collection
$collection->addUrlRewrite();
It has helped me.
$id = 10;
Mage::app()->setCurrentStore('admin');
$url = Mage::helper('catalog/product')->getProductUrl($id);

CodeIgniter: current_url shows question mark

Say my page is on:
http://localhost/app1/profile/index/123/
The result of current_url() is this:
http://localhost/app1/?profile/index/123
There is a ? that shouldn't be there. The question mark seems to be caused by the following config setting:
$config['enable_query_strings'] = TRUE;
I need query strings enabled in my application. Any ideas what I need to do?
EDIT 1:
Also, in the case when the URL does have a query string, I need current_url to also return that. I'm hoping Phil Sturgeon's solution here CodeIgniter current_url doesn't show query strings will help me.
I'm using CI 2.1.0.
As mentioned, $config['enable_query_strings'] is sort of a "legacy" setting in Codeigniter from back when there was no support $_GET (really, none).
http://codeigniter.com/user_guide/general/urls.html
Enabling Query Strings
In some cases you might prefer to use query strings URLs:
index.php?c=products&m=view&id=345
c === Your controller name
m === Your method name
The rest is the method arguments. It's a very misleading description, and there's no mention of the other setting or query strings at all in the rest of the URL docs. I've never heard of anyone actually using this. CI comes with $config['allow_get_array']= TRUE; by default, which is what you want.
You can modify the current_url() function for query string support, just create application/helpers/MY_url_helper.php and use this:
function current_url($query_string = FALSE)
{
$CI =& get_instance();
$current_url = $CI->config->site_url($CI->uri->uri_string());
// BEGIN MODIFICATION
if ($query_string === TRUE)
{
// Use your preferred method of fetching the query string
$current_url .= '?'.http_build_query($_GET);
}
// END MODIFICATION
return $current_url;
}
Then call it like current_url(TRUE) to include the query string.
Don't use: $config['enable_query_strings'] = TRUE;
Use this instead: $config['allow_get_array']= TRUE;
enable_query_strings is not what you think and is not used much.
To build your own query strings, use one of these two:
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
along with this:
$lastseg_with_query = $lastseg.'?'.$query_string;
Please consult this SO Q&A for more information: URI Segment with Question Mark

Resources