Welcome Guest, Not a member yet? Register   Sign In
Database And Routes
#1

[eluser]ShoeLace1291[/eluser]
I'm trying to make a content management system(CMS). I have three tables as follows:

Categories - Will show up in navigational menu as News, Reviews, Tutorials, etc.
SubCategories - Child of categories, under reviews would be Xbox 360, PS3, etc.
Pages - Child of subcategories; under xbox 360 would be a page such as Halo 3

i have my routes set up to pick up urls like this:
mysite.com/reviews/xbox-360/halo-3

The reviews uri segment is one of the categories so it goes like this:
category/subcategory/page

What would be the best way to structure my application directory as far as controllers, models, and libraries are concerned?
#2

[eluser]flaky[/eluser]
why create 2 tables for categories, you could have the categories table like this
Code:
category_id smallint
category_name varchar(50)
category_parent_id smallint

//the sql code
CREATE TABLE `category` (
  `category_id` smallint(6) NOT NULL AUTO_INCREMENT,
  `category_name` varchar(50) COLLATE utf8_bin NOT NULL,
  `category_parent_id` smallint(6) DEFAULT NULL,
  PRIMARY KEY (`category_id`),
  KEY `FK_category_parent_id` (`category_parent_id`),
  CONSTRAINT `FK_category_parent_id` FOREIGN KEY (`category_parent_id`) REFERENCES `category` (`category_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
whenever category_parent_id is null that is a category, else it's a sub-category
#3

[eluser]ShoeLace1291[/eluser]
|---Categories--| //Reviews, News, Tutorials, etc. When viewing the "news" category, url would be mysite.com/pages/news ---- function is called "category" and lists all subcategories that fall under this category.
|
|
SubCategories(subCategoryID, categoryID) //Under a category such as reviews: Xbox 360, PS3, etc... url would be mysite.com/pages/reviews/xbox-360 ---- function is called "subcategory" and lists all the pages under that subcategory.
|
|
Pages(pageID, subCategoryID) //News articles, xbox 360 reviews, etc... url would be mysite.com/pages/reviews/xbox-360/halo-3 ---- function is called "view" and would display the entire page.

Above is a tree I created that would explain how my tables and urls are linked. I currently do not have it set up correctly which is why i'm posting this. all of the above urls are contained in a controller called pages.

These page titles are all powered by databases, so I can't just make a route that reroutes pages/news to pages/category, but it would be pages/category that I would be routing to. This is my current routes config file:

Code:
$route['default_controller'] = "main";
$route['scaffolding_trigger'] = "";

$route['register/activate/:any'] = 'register/activate';
$route['logout'] = 'main/logout';
/*$route['pages/news'] = 'pages/category';
$route['pages/news/:any'] = 'pages/subcategory';
$route['pages/reviews'] = "pages/category";
$route['pages/reviews/:any'] = "pages/subcategory";
$route['pages/tutorials'] = "pages/category";
$route['pages/tutorials/:any'] = "pages/subcategory";*/

$route['pages/:any'] = "pages/category";
$route['pages/:any/(:any)'] = "pages/subcategory'";

You can see how I had done it prior to using the pages/:any. I can't do it that way because everytime a new category is created, I would have to create a new route.

Hopefully I've explained my situation well enough for you to answer. Thanks for your time.




Theme © iAndrew 2016 - Forum software by © MyBB