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
4
votes
1 answer

CodeIgniter routes are not working

I've defined following route in config file as follows. $route['apartments/(:any)'] = 'apartments/view/$1'; If I give http://localhost/apartment_advertisement/apartments/shobha_complex like this in url it works perfectly fine. If I give…
user1275378
3
votes
2 answers

Redirect in Codeigniter

I have a paginated display in which on each page call I set the current URI string into a session (in my controller). $current = $this->uri->uri_string(); $this->session->set_userdata('return_to', $current); From the view the user can click a link…
Rooneyl
  • 7,802
  • 6
  • 52
  • 81
3
votes
2 answers

how to include a file inside a model in codeigniter?

I’m new to codeigniter and maybe my question is a bit stupid but..I cant understand how I can include a file inside a model. Inside del model folder I’ve a subfolder named include and inside this I’ve some php file. The structure is something like…
gaggina
  • 5,369
  • 10
  • 31
  • 31
3
votes
4 answers

Relative path or url for html src and href attributes

Using a framework makes it easy to list full url's for my html src and href attributes, and I feel I'm being more thorough by listing a full url instead of a relative path. But is this faster? Am I incurring an extra DNS lookup? What is the best…
steampowered
  • 11,809
  • 12
  • 78
  • 98
3
votes
1 answer

Unable to load the requested file - CodeIgniter

I'm trying to include a PHP file called includes.php which is not contained within the normal Views folder. The file contains links to the JS files to be loaded with this particular theme. includes.php resides within the scripts folder: | assets | …
Joe W
  • 998
  • 6
  • 16
  • 36
3
votes
1 answer

load page content using jquery in codeigniter error

I had a home page which have a few tables that refresh itself every few sec. Below is the code for the jquery in view file (inside_view.php)