It has two functions. The first function gets the URL and breaks it into parts. The second function includes the required file based on the URL parts.
public function urlParts()
$this->uri = $_SERVER['REQUEST_URI'];
$this->path = parse_url($this->uri, PHP_URL_PATH);
$temp_path = trim($this->path, '/');
$this->uri_parts = explode('/', $temp_path);
The variable $this->uri_parts contains the first part of URI. This is category of article. The variable $this->uri_parts is the second part of URI, which can be either article or sub category. The third part, $this->uri_parts, is the article.
public function route()
// Home Page Layout
if ($this->uri_parts == "")
$this->include = "/layout/home.php";
// Category Layout
else if (isset($this->uri_parts))
$this->include = "/layout/category.php";
If the first part of URI (category) is set, then category page is included, else home page is included.
The first part of URL is always the category. It can be:
- Parent category containing sub categories
- Main category containing articles
How To Find Type of Category
Find categories in the category table, which have parent ID equal to the category ID. If the category contains sub categories, then it is parent category, otherwise it is main category.
What To Display
At this stage, there can be four possibilities based on two deciding factors: type of category and second part of URI.
- If second part of URI is not set
- Category page with list of sub categories
- Category page with list of articles
- If second part of URI is set
- Include article page if main category
- Include category page if parent category