Welcome Guest, Not a member yet? Register   Sign In
Building a SQLite CMS: Best Way To Have Multiple Levels In My Url (category/post, category/category/post) etc.
#1

[eluser]Vheissu[/eluser]
I am building a custom SQLite CMS ontop of Codeigniter and I have everything working fine. Modular functionality, media uploading capabilities, templating and other stuff you would expect in a CMS, however I have hit a roadblock.

I would like my CMS to have urls that function similar to the way Wordpress works so the ability to have multiple category inheritance for posts is important. I can't get my head around the issue though, here is how I would like them to function.

At present urls work like this: http://localhost/sqlitecms/pagename - so visiting http://localhost/sqlitecms/about shows you the about page. But my issue is that what if it belongs to a category or perhaps a sub-category?

For example if my about page belongs to a category titled /what-we-are-about or it belongs to the category /what-we-are-about/who-we-are/about how would my controller functions and routes check for this? I tried multiple ways and they all failed.

I am using Codeigniter 2 (latest from Bitbucket) and I am using Modular Extensions as well.

My current routing structure is as follows:

Code:
$route['default_controller'] = "pages/pages";    // Pages controller is the default controller
$route['admin']              = "admin";          // Main admin controller
$route['(:any)/admin']       = "$1/admin";       // Individual module admin controllers
$route['(:any)']             = "pages/pages/$1"; // Every request to the pages controller

Inside of my pages controller I have the following _remap function which loads page data and everything else:

Code:
public function _remap($method)
    {
        // If a page like /about is only accessed
        $segment  = $this->uri->rsegment(2, 1);
        
        // If a page like /about/board-of-directors is accessed
        $segment2 = $this->uri->rsegment(3, 2);
        
        if ($segment == 'index' AND $segment2 == 'index' || $segment2 == '') {
            $segment = "home";
        }
        
        $page  = $this->mpages->fetch_page($segment);

        // Page meta like keywords and descriptions
        $meta['page_title']       = $page[0]['page_title'];
        $meta['keywords']         = $page[0]['page_keywords'];
        $meta['description']      = $page[0]['page_description'];
        $meta['page_name']        = $page[0]['page_name'];
        $meta['site_name']        = $this->settings['site_name'];
        
        // Page content - page content and page template name
        $content['page_content']  = $page[0]['page_content'];
        $content['page_template'] = $page[0]['page_template'];
        
        // Store our Codeigniter object inside of CMS
        $content['CMS']           = $this->CMS;
        
        // Get our modules
        $content['modules']       = $page['modules'];
        
        $this->parser->parse('header', $meta);
        $this->parser->parse($content['page_template'], $content);
        $this->parser->parse('footer','');
        
    }

I have a module called 'pages' inside of a modules folder in the application directory with a controller called 'pages' hence the pages/pages reference in my routes file.
#2

[eluser]cahva[/eluser]
Heres a quickie as I'm off to bed. Save the full seo url to pages table and you can do a simple search from that. Roughly something like this:

Code:
public function _remap()
{
    $uri = $this->uri->uri_string();
    $p = str_replace('/pages/','',$uri); // remove the current controller from uri

    if ($p[0] == '/')
    {
        $p = substr($p, 1);
    }
    
    // If $p is empty use the frontpage, else fetch the page according to uri
    $page = ($p == '') ? $this->mpages->fetch_page('home') : $this->mpages->fetch_page($p);

    ...
}

Now if you have page "about" in a category, it's seo url(or slug whatever you want to call it) would be for example "category1/sub-category/about" and you access the page according to that. I can surely say that if you save only the current page's seo title, you'll be in trouble when you have to traverse through the pages parents everytime to get the actual page from db if its located in subcategory.




Theme © iAndrew 2016 - Forum software by © MyBB