Welcome Guest, Not a member yet? Register   Sign In
$route[':any'] issue
#22

[eluser]Randy Casburn[/eluser]
Hi EEssam,

Just for fun, I thought I would put something together to demonstrate how to do this. I'm certain there are 10 ways, but this is one. The design concept is simply to have a somewhat static facing web that would be fantastic for SEO purposes. The true application that resides behind this static site, built with CI, of-course, would never be built this way but would be discovered because of the great SEO attributes the single-word-from-root web page name provides.

Disclaimer: Put some error checking in here somewhere!

Controller:
Code:
class Home extends Controller
{
    var $pageData;
    var $uriSegments;
    
    function Home()
    {
        parent::Controller();
        $this->uriSegments = $this->uri->total_segments();
    }

    function index()
    {
        $this->pageTop();
        $this->load->view('content/public/home');
        $this->pageBottom();
    }
  
   /* Routes.php is used to reroute [:any] method here. Any tiered levels off
    * the root of your web must be accounted for in this structure. In this
    * example, there is the 'home' page, a set of 'articles', and a 'portal'.
    * Note the left menu will only be seen on the 'home' page and the default
    * pages.  The left menu will not be seen on the 'articles' pages or the
    * portal page.
    */
   function load_page(){
        /* I Use ajax for all page updates. So each time a link is click
         * that would return to the home page, the index() method is bypassed
         * due to the routing.  So this must be here to accommodate both the
         * ajax requests and the rerouted URIs.
         */
        if ( $this->uri->segment($this->uriSegments) == 'home' ){
            $view_to_show = 'home';
            $this->load->view('content/public/left_menu');
        }
        elseif ( strstr($this->uri->uri_string(),'articles') ) {
            $view_to_show = 'articles';
        }
        elseif ( strstr($this->uri->uri_string(),'portal') ) {
            $view_to_show = 'eyeOSlogon';
        }
        else {
            $view_to_show = 'content';
            $this->load->view('content/public/left_menu');
        }

        if($this->uri->segment($this->uriSegments) == 'articles') $this->getPageData('strategy');
        else $this->getPageData($this->uri->segment($this->uriSegments));
        $this->load->view('content/public/'.$view_to_show, $this->pageData);
   }

   function getPageData($page){
      $this->load->model('Getmystuff');
      $this->pageData = $this->Getmystff->getPageDataFromDB($page);
   }

Model function from file Getmystuff.php
Code:
function getPageDataFromDB($page)
    {
    /* presumes a DB with a table named content
     * with at least a row named 'alias' that has
     * the lower case page name
     */
        $query = $this->db->getWhere('content','alias="'.$page.'"');
        $aPageMeta = $query->row_array();
        return $aPageMeta;
    }

For the views: Note I'm passing $this->pageData array. The pageData array is simply constructed from the DB rows returned by the model. Use the variable representations of those rows within your views to show the content in your view templates.

I hope this more thoroughly answers your question. Most importantly, shows you how awsome CI can really be once you understand it's flexibility.

So here is one 'realization' of use CI and construct your URLs with the page name right after the FQDN thus:
http://mydomainname.com/mypage or http://mydomainname.com/mypage.html

Regards,

Randy


Messages In This Thread
$route[':any'] issue - by El Forum - 06-16-2008, 11:14 AM
$route[':any'] issue - by El Forum - 06-16-2008, 12:25 PM
$route[':any'] issue - by El Forum - 06-16-2008, 12:59 PM
$route[':any'] issue - by El Forum - 06-16-2008, 02:11 PM
$route[':any'] issue - by El Forum - 06-16-2008, 02:13 PM
$route[':any'] issue - by El Forum - 06-16-2008, 02:17 PM
$route[':any'] issue - by El Forum - 06-16-2008, 02:42 PM
$route[':any'] issue - by El Forum - 06-16-2008, 02:56 PM
$route[':any'] issue - by El Forum - 06-16-2008, 03:08 PM
$route[':any'] issue - by El Forum - 06-16-2008, 04:00 PM
$route[':any'] issue - by El Forum - 06-16-2008, 04:11 PM
$route[':any'] issue - by El Forum - 06-16-2008, 05:41 PM
$route[':any'] issue - by El Forum - 06-16-2008, 07:01 PM
$route[':any'] issue - by El Forum - 06-16-2008, 07:22 PM
$route[':any'] issue - by El Forum - 06-16-2008, 07:32 PM
$route[':any'] issue - by El Forum - 06-16-2008, 07:45 PM
$route[':any'] issue - by El Forum - 06-16-2008, 07:49 PM
$route[':any'] issue - by El Forum - 06-16-2008, 08:19 PM
$route[':any'] issue - by El Forum - 06-16-2008, 08:20 PM
$route[':any'] issue - by El Forum - 06-16-2008, 09:25 PM
$route[':any'] issue - by El Forum - 06-16-2008, 09:47 PM
$route[':any'] issue - by El Forum - 06-17-2008, 09:29 AM
$route[':any'] issue - by El Forum - 06-17-2008, 09:40 AM
$route[':any'] issue - by El Forum - 06-17-2008, 10:12 AM
$route[':any'] issue - by El Forum - 06-17-2008, 11:04 AM
$route[':any'] issue - by El Forum - 06-17-2008, 03:29 PM
$route[':any'] issue - by El Forum - 06-17-2008, 03:38 PM
$route[':any'] issue - by El Forum - 06-17-2008, 03:49 PM
$route[':any'] issue - by El Forum - 06-17-2008, 04:02 PM
$route[':any'] issue - by El Forum - 06-17-2008, 05:20 PM
$route[':any'] issue - by El Forum - 06-17-2008, 05:58 PM
$route[':any'] issue - by El Forum - 06-17-2008, 08:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB