Questions tagged [codeigniter-url]

By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard "query string" approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a segment-based approach: example.com/news/article/my_article

CodeIgniter URLs can be simplified a number of ways, either via helpers, or routing.

URL Helper

Makes your life easier by bringing functionality to your fingertips without typing out lengthy repetitious urls or anchor code. Things like:

  • site_url()
  • base_url()
  • current_url()
  • anchor() ouputs something like <a href="http://example.com">Click Here</a>
  • and more...

Routes

Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:

example.com/class/function/id/

However you may want something crazy like this:

example.com/page/when-i-use-php-i-sneeze/12/4/2011/bob

Routes help you achieve that and still point to the proper class/method in an example like so:

$route['product/:num'] = "catalog/product_lookup";

You can match literal values or you can use two wildcard types:

  • (:num) will match a segment containing only numbers.
  • (:any) will match a segment containing any character.
406 questions
47
votes
1 answer

array_unique showing error Array to string conversion

For getting the unique values i am using unique values. Below is the code i am using array_unique($results_external); aasort($results_external,"created_on"); $returns_buy_external[]=array_reverse($results_external, true); If i use the code like…
user3652109
  • 477
  • 1
  • 4
  • 6
23
votes
3 answers

How to route 2 parameters to a controller?

This seems really basic but i can't get the hang of it. I'm trying to send more then one parameter to a method in the controller, like this : http://localhost/ci/index.php/subjects/3/state This is the routings i've tried : $route['subjects/(:num)']…
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
12
votes
1 answer

CodeIgniter sending POST data to specific URL - API data

I need to send data to URL, i have done this before by method GET and using url_encode() Now that I need to POST with the framework CodeIgniter, I am not very well aware what to use Any help will be appreciated
Sanjeev
  • 534
  • 1
  • 5
  • 16
9
votes
2 answers

Want to create dynamic subdomain in codeigniter?

In my site i want to add an functionality for user to use their username with domain. Like in codeigniter right now i want to give the user to use their own url to login in site and do other stuff. For eg: i Want www.username.mysite.com/login or…
Nilay Patel
  • 151
  • 2
  • 6
8
votes
4 answers

Route to multiple sub folders in CodeIgniter

I have a admin folder set up in my controllers directory, under that i have 3 seperate sub-folders with controllers inside of them. -- Controllers ---- Admin ------ Dashboard -------- dashboard.php -------- file.php ------ Members --------…
CodyRob
  • 249
  • 1
  • 2
  • 8
8
votes
3 answers

CodeIgniter Session Failing only in China

OK I've spent 3 days trying to find out what's going on here and I'm stumped. The site is built with CI. (http://horizoneslchina.com) For a while I was getting Disallowed Key Characters whenever anyone in China. I extended the core Input class with…
Solvision
  • 193
  • 1
  • 11
6
votes
6 answers

is_home() function in Codeigniter

As I know the Wordpress has is_home() function to determine home page. In YII i use solution like this Yii check if homepage In CI, templates actually, i faced many times with necessity of it. For example, adding some css classes in tag . All…
Andrei Zhamoida
  • 1,457
  • 1
  • 20
  • 30
6
votes
2 answers

Routes in Codeigniter

I want to have a clean URL in CodeIgniter based application for User's Profile Information. Please Take a look at URL formats below. Actual URL : http://www.mydomain.com/index.php/users/profile/user1 I'm expecting users to have Personal URL's…
pinaldesai
  • 1,835
  • 2
  • 13
  • 22
5
votes
3 answers

Codeigniter URL not working without index.php

I've just set up a new webiste http://www.reviewongadgets.com But there is a problem with URL rendering When I put an URL as below it's not working and gives page not found error http://www.reviewongadgets.com/latest-mobile But it works…
Vicky
  • 9,515
  • 16
  • 71
  • 88
5
votes
10 answers

How to make CodeIgniter accept "query string" URLs?

According to CI's docs, CodeIgniter uses a segment-based approach, for example: example.com/my/group If I want to find a specific group (id=5), I can visit example.com/my/group/5 And in the controller, define function group($id='') { ... …
zihaoyu
  • 5,483
  • 11
  • 42
  • 46
5
votes
2 answers

Codeigniter File Paths

sorry to bother but I am having some confusion with filepaths within codeigniter, as you may or may not know CI lays out its file system as follows: -application: -controllers -views -models -system(contains CI…
TotalNewbie
  • 1,004
  • 5
  • 13
  • 25
5
votes
1 answer

product detail page routing in codeigniter

In my local site http://localhost/giftsware/nl/products/details/2382 This is my browser url for product description page now I want more user friendly url for product description page. I want to change above url to…
4
votes
4 answers

Codeigniter url path

This is the most simple way I can ask this question as I have not fully understood what's going on, or what I am not doing right. I'm having trouble with the url. http://localhost/index.php/user is the same as…
Andrei Cristian Prodan
  • 1,114
  • 4
  • 17
  • 34
4
votes
3 answers

How to hide data from URL string on Codeigniter

I am beginner on Codeigniter so I need help. I am making blog site with Codeigniterand I don't know how to hide controller class, and ID from URL. Like I have generated following URL:…
Mr.Happy
  • 517
  • 1
  • 9
  • 25
4
votes
2 answers

In codeigniter redirecting is not working without index.php?

I am new to codeigniter while redirecting a page index.php is not loading by default,So i have tried the below code in htaccess file. I have installed php 5.3.10, apache server and postgres database. so if any new configuration have to be done apart…
1
2 3
27 28