Route how to Change URL - codeigniter

I would change my URL in CodeIgniter
I have the following URL:
http://example.altervista.org/girls/show/Megan
I would have:
http://example.altervista.org/show/Megan
I don't want the name of the controller displayed
How can i do this?

I think it should be
$route['show/(:any)'] = 'girls/show/$1';

Related

How to call function in laravel controller from codeigniter view?

My view Codeigniter is like this :
<form id="search_form_hotel" name="search_form" method="post">
...
</form>
...
<script>
...
$.ajax({
url: base_url + 'hotel_booking/hotel/search_hotel',
type: "post",
...
</script>
This :
url: base_url + 'hotel_booking/hotel/search_hotel',
hotel : controller name in laravel framework
search_hotel : method name in laravel framework
Whether it can call a function in the laravel controller from codeIgniter view?
Any help much appreciated
Cheers
No, you can not. Inject controller's function in views are completely outside of arquitectura. Also, laraval does not register the routes in the same way as codeigniter does.
In codeigniter the url pattern defines the structure of a controller, however in laravel you are need to register every route separately without taking in consideration the url format.

how to make url as pretty url in codeigniter

I am new to ci. naybody knows how to minify the url.
for example : yourdmain.com/blog/view/blog-title
I need this url to be like this : yourdmain.com/blog-title
please explain how to do this
this can be many like blog, categories, pages, posts
please help..
Use route.php under your config folder
$route['blog-title] = 'blog/view/blog-title';
if you need dynamically loading based on a title
$route['(:any)/index.html'] = 'blog/view/$1';
// will route any url with /index.html to your controller
$route['(:any).html'] = 'blog/view/$1';
// will route any url with title.html to your controller then pass your title as your function variable
Why index.html or .html
This is my way i use to distinguish my other urls to my blog titles urls .. meaning only urls with extension index.html or .html will be routed to my blog/view path
You can have hyphens instead of underbars putting these lines in the file routes.php
$route['(.+)-(.+)-(.+)-(.+)-(.+)'] = "$1_$2_$3_$4_$5";
$route['(.+)-(.+)-(.+)-(.+)'] = "$1_$2_$3_$4";
$route['(.+)-(.+)-(.+)'] = "$1_$2_$3";
$route['(.+)-(.+)'] = "$1_$2";

Change Codeigniter url

I'm using Codeigniter.I want to set href attr to something like :
<a href="/contact.html" >Contact</a>
But i get 404 error because i should write
Contact.
Where is some thing to fix this problem.
Any help please.
Assuming that you have a controller by the name Contact and you successfully extend the CI_Controller class, go to application/config folder and in config.php find:
$config['base_url'] = 'http://www.youdomain.com/';
Then in your internal links you should do:
Contact
If you are using javascript to make the redirect, put on top of the js file:
var host = 'http://www.yourdomain.com/';
Again:
window.location.href = host + 'contact';
If you're using codeigniter, you do not want to point to an .html file.
If you're using codeigniter correctly, you should use the helper methods that exist in codeigniter.
Instead of writing the anchor tag yourself, try this:
<?php echo anchor('contact', 'Contact'); ?>
to add the suffix to your controller in calling go to config/config.php and search for
$config['url_suffix'] = '';
and assign html to it to become
$config['url_suffix'] = 'html';

Codeigniter admin controller in subfolder issue while pagination

I am new to codeigniter.i have create subfolder for admin controller like
Controller->admin->news.php
Now when i am access the news controller its working fine like
http://mysite.com/sacha/adminenter code here/news
But when i am trying edit delete or pagination like
http://mysite.com/sacha/admin/news/index/1
or
.../sacha/admin/news/1
Its showing 404 page not found error
Routes which i am using is
$route['admin/news'] = 'admin/news';
$route['admin/news/index'] = 'admin/news/index';
$route['admin/news/(:num)'] = 'admin/news/$1';
$route['admin/news/index/(:num)'] = 'admin/news/index/$1';
I used (:any) also but none is working.
Thanks
remove your four line you specified above and just update your routes as this,.
$route['admin/news/index/(:num)'] = 'admin/news/index/$1';
$config['uri_segment'] = 4;
You have to include this config parameter in pagination.

How to route everything to default controller in codeigniter?

I have a website http://example.com built using codeigniter 2. the default controller is
$route['default_controller'] = "domain";
If I try to access pageX, the link should be http://example.com/en/domain/view/pageX.
I want to allow the visitor of the website to access this page by typing
http://example.com/pageX
I have tried
$route['(:any)'] = "view/$1"; ==> it gives 404 Page Not Found
$route['(:any)'] = "domain/view/$1"; ==> it redirects to homepage with link shown as http://example.com/en/pageX
$route['(:any)'] = "en/domain/view/$1"; ==> it gives 404 Page Not Found
but non of them worked for me.
EDIT
by adding this:
$route['(:any)'] = 'domain/view/$1';
$route['en/blog'] = 'domain/view/blog';
example.com/blog will work fine
but I need it to be more general to cover all pages except admin page, something like this:
$route['(:any)'] = 'domain/view/$1';
$route['^(?!admin).*'] = 'domain/view/$o';
//The above routes will show the home page only for whatever i try!!
What is the route that i have to add to routes.php?
$route['default_controller'] is invoked if there is no URI present. Use $route['404_override'] for a full "catch all."
To get your routing pattern working, try this:
$route['[^/]*/(.*)'] = 'en/domain/view/$1';
I have managed my problem by doing this
$route['^[a-z]+$'] = 'domain/view/$1';
$route['([a-z]{2})/([a-z_]{1,50})'] = 'domain/view/$2';

Resources