Welcome Guest, Not a member yet? Register   Sign In
Need help about url routings
#1

[eluser]smdbzdmr[/eluser]
Hi

I just start codeigniter and read/watch tutorials. I think i learn ci basics Smile But i need help about this routings

I always use same url structure.

Home
Code:
http://localhost/codeigniter/

For example general pages
Code:
http://localhost/codeigniter/contact
http://localhost/codeigniter/about
http://localhost/codeigniter/gallery (just photo list)

And category system or other pages
Code:
http://localhost/codeigniter/products/ (category)
http://localhost/codeigniter/products/notebooks/ (category)
http://localhost/codeigniter/products/dell-inspiron-6400-notebook (product page (no / at the end of it))


My old theme system has 4-5 files like
Code:
tpl.index.php (home)
tpl.page.php (general pages (contact, about...))
tpl.product.page.php (product page)
tpl.products.php (products list (category template))


I just want to know how can i make this with codeigniter? I think i need Page, Category, Product_page, Home (i am not sure about home) controllers and some views and models. Views and models not important i can write them but can you help me about routings?

(sorry for my english)

Regards

#2

[eluser]Samus[/eluser]
Tbh, you could very well do this on 1 controller and just route everything as you'd want it.

e.g

Code:
class Home extends CI_Controller {

function index() {
//index page
}

function contact() {
// contact page
}

function about() {
// about us page
}

function category($category = '') {
// functionality for the category page
}

function products($slug = '') {
// functionality to retrieve information on the current product being viewed
}

}

Then just route it all together.

Code:
$route['contact'] = "home/contact";
$route['about'] = "home/about";
$route['category/(:any)'] = "home/category/$1";
$route['products/(:any)'] = "home/products/$1";
#3

[eluser]smdbzdmr[/eluser]
@Samus, thanks.
some general pages are saved on db. so i need to get them with their slug.

is this route true ? and i think with this route there wont be automatic 404 pages ? if i cant get any page from db i load my_404_view. am i right ?

Code:
$route['contact'] = "home/contact";
$route['about'] = "home/about";
$route['category/(:any)'] = "home/category/$1";
$route['products/(:any)'] = "home/products/$1";
$route['(:any)'] = "home/read_page/$1";
#4

[eluser]Samus[/eluser]
[quote author="smdbzdmr" date="1333977429"]
$route['(:any)'] = "home/read_page/$1";
[/code][/quote]
If you have this any page you visit will be routed to "home/read_page/any" including your about, contact, categories & products pages.

More like:

Code:
$route['general/(:any)'] = "home/read_page/$1";
#5

[eluser]smdbzdmr[/eluser]
Code:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['page'] = "page";
$route['page/read/(:any)'] = "page/read/$1";
$route['(:any)'] = "home/read_page/$1";

Code:
http://localhost/codeigniter/about // This is a general page and it seems like under root directory
http://localhost/codeigniter/contact

http://localhost/codeigniter/page/read/test-page // Just for test... It could be anything like products/dell-inspiron-1234 or photos/some-photo-title...

This works for me Smile Thanks alot Samus. Maybe it looks like hardcore code but its ok for beginning Smile


Edit :
Code:
http://localhost/codeigniter/qweasdzxc123
Like this link system load "home > read_page" but it returns nothing from db. i can load 404 page when there is no result for slug. I think only bad thing is 404 page for this Smile




Theme © iAndrew 2016 - Forum software by © MyBB