In my website I need to customise the url ,
I done it some way ,everything is working fine .I got what I need ,but I want to do it in a proper way .
Below is my code
$route['admin/lessons'] = 'admin/admin/lessons';
$route['admin/lesson_mgmt'] = 'admin/admin/lesson_mgmt';
$route['admin/labs'] = 'admin/admin/labs';
$route['admin/tools'] = 'admin/admin/tools';
Here in this way I am managing the custom url section .
I want to make this url dynamic so that ,the code will not be longer ,there are other section .
If i will do it in this way ,I have to write a lot .
Here i want to replace everything in a single line.
Can anyone suggest me anything ?
Thank you in advance.
Try like this...
In your application/config/routes.php
$route['admin/([a-zA-Z0-9_-]+)'] = 'admin/admin/$1';
Hope it will work fine..
In above code.. [a-zA-Z0-9_-]+) this is regular expression having combination of one or more alphanumeric characters(alphabets+numbers).If route gets admin/characters...it redirect to admin/admin/characters.
Related
hi i create one custom page in WordPress like page-download.php
i access this page like
http://example.com/download
its word fine but i want access this page like
http://example.com/download?n=skype
http://example.com/download?n=firefox
etc every time n value change.
and also i want get n value in page-download.php
please tell me how to do it . i know how to work in php simple but in wordpress its not work
Why just not use, echo $_GET['n'] ?
When you hit this page directly from the URL like below, please change your parameter, because of that I have tried same method few days ago and I can't get the parameter value.
http://example.com/download?from_browser=skype
http://example.com/download?from_browser=firefox
You can get the value like below or as per the reference :
$blah = get_query_var( 'from_browser');
if(isset($blah)) // Your code will be here
Hope this help!!!
I'm Using Codeigniter 3.x , Using routes.php I want to create dynamic routes, for example I have a class name Class1.
I want output url
mysite.com/Class1-Student-Search
But using hyphen(-) is not working
If I put a slash(/), it works,
$route['(:any)/Student-Search'] = "search";
it returns
mysite.com/Class1/Student-Search
and using underscore (_) also work.
$route['(:any)_Student-Search'] = "search";
returns
mysite.com/Class1_Student-Search
But I want to use hyphen(-), if I put it, it will go to 404 error page, I used these four solutions but not work for me.
$route['(:any)-Student-Search'] = "search";
$route['([a-zA-Z]+)-Student-Search'] = "search";
$route['([a-zA-Z-0-9]+)-Student-Search'] = "search";
$route['(.*)-Student-Search'] = "search";
And if i hardcode the value in route
$route['Class1-Student-Search'] = "search";
Then it also working
You trying to create a dynamic routes which is not possible in codeigniter if you see the following flow chart of codeigniter you understand what i mean.
also you can see this chart in codeigniter official website
when you try to redirect or call some url it's work like this
Every request first goes to route there for you can't make it dynamic
Here is my solution, it is working for me, do like this.
$route['(:any)-Student-Search'] = "search";
then in your link button, hopefully in your view, href the link like this.
href="/<?php echo $row->classname; ?>-Student-Search"
the point is that not only you have to make your routes, also suffix it in your href link also the same way.
In my codeigniter webapp, I'm using multi language site. Default and in english like these:
www.xxx.com (default)
www.xxx.com/en (english)
And I have a controller where I want to re-route specific calls say potato and tomato to vegie like these:
www.xxx.com/potato/param => www.xxx.com/vegie/param
www.xxx.com/tomato/param => www.xxx.com/vegie/param
So far, I have managed to reroute with default language url using like this in my route.php:
$route['potato/(.+)$'] = 'vegie/$1';
$route['tomato/(.+)$'] = 'vegie/$1';
But I doesn't work for the english site. I did like this, and not working:
$route['en/potato/(.+)$'] = 'en/vegie/$1';
$route['en/tomato/(.+)$'] = 'en/vegie/$1';
Anyone can help me for this? Thanks.
First, create new function to manage the english version, ex: function vegie_en()
then route to it
$route['en/potato/(:any)'] = 'vegie_en/$1';
I have found the problem. I have this in my route.php which makes it rerouting wrongly if there's prefix en/:
$route['en/(.+)$'] = '$1';
I moved this to the end of the route.php and it working very fine now.
I had faced same problem in my project. I fixed it by removing the 'en' and put $2 as for dynamic value.
So in your case, this will work.Please try this given below code.
$route['en/potato/(.+)$'] = 'vegie/$2';
$route['en/tomato/(.+)$'] = 'vegie/$2';
I am getting the LargeImage URL using Amazon's advertising API. I want to modify the URL to replace
.jpg
with
._SS300_.jpg
to show the correct size I need for my template. I am using Wordpress and a plugin called AmazonSimpleAdmin.
I believe this is the part of the plugin code I need to do something to:
$replace = array(
// ...
($item->LargeImage != null) ? $item->LargeImage->Url->getUri() :
get_bloginfo('wpurl') . $this->plugin_dir . '/img/no_image.gif',
I don't know much PHP, but as far as I can tell the large image URL is part of the array, and I know the part I need to change is
$item->LargeImage->Url->getUri()
but that's as much as I've been able to figure out. Any help is appreciated.
$string = '.jpg';
$string = str_replace('.jpg', '._SS300_.jpg', $string);
// Do something with $string.
I have an url like this:
http://kees.een-site-bouwen.nl/home/categorie/11
to show factories in a specific category.
I want to have an url like this:
http://kees.een-site-bouwen.nl/categorie/11
but when i use the url routing in my config/routes file like this:
$route['categorie'] = 'home/categorie';
it does not work. am i missing something?
The working link to the page is:
echo '' .$value->Categorie. '';
The link that does not work is:
echo '' .$value->Categorie. '';
Hope someone can help me :)
$route['categorie/(:num)'] = 'home/categorie/$1';
Here is one easy, fast and clean route :)
Please read Documantation before asking.. CI Routing
You are missing to to mention the argument i.e 11 to like this
$route['categorie/(:num)']