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

[eluser]zend[/eluser]
Hello

I need help for dinamyc pages.
I want you all to my page rendered in one div tag. $page (all in one)
Like this :
http://woork.blogspot.com/2007/10/load-p...d-php.html
Without a load on the other.

Clicking on a link replace the old page in a new page.

How could this be done in codeigniter?
#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
  
}
}




Theme © iAndrew 2016 - Forum software by © MyBB