Welcome Guest, Not a member yet? Register   Sign In
Load pages using URL variables
#2

[eluser]Rolly1971[/eluser]
i do something like this for one of my sites i am working on. url's look like this:

http://www.example.com/pagename

my controller reads in the uri segment:

$page = $this->uri->segment(1);

then passes that variable to a page_model class function:

$content = $this->page_model->get_content($page);

ofc i do some checking on the uri segment before passing it, but the content itself is stored in a database which this function call retrieves and returns (along with some per page settings)

once the content is returned it is passed to My_Controller that finishes up with it and send the page to the browser.

so my controller looks something like this:

notes: My_Controller class resides in application/core and extends CI_Controller, all my controllers in application/controllers extend from it.

Code:
class Welcome extends MY_Controller {

function __construct()
{
  parent::__construct();
}

public function index()
{
  
  $val = $this->uri->segment(1);
  
  if (is_null($val) OR empty($val))
  {
                       // if the $val (uri->segment(1)) is not there or empty default to home page content
   $val = 'home';  
  }

                /* ADDITION CODE HERE THAT IS NOT PERTINENT */
                
  $content = $this->page_model->get_page_content($val);
    
  /* ADDITION CODE HERE THAT IS NOT PERTINENT */
  
  $this->load_page($content); // this function is in My_Controller Class
  
}
}


Messages In This Thread
Load pages using URL variables - by El Forum - 02-11-2012, 11:15 AM
Load pages using URL variables - by El Forum - 02-11-2012, 05:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB