Welcome Guest, Not a member yet? Register   Sign In
dynamic pages (from db) problem
#1

[eluser]gn90at[/eluser]
Hi together Smile

first of all: my english is bad. i am from austria...i hope u can read it.

i am working with CodeIgniter since 2 weeks. i made a few small projects and now i want to create my own cms for one site (admin_panel).

in the admin panel i can create a new site (eg "About") and i save the site with some content in a DB. (id, name, content).

in the frontend, i got my own Sites Controller and a Site_model.

Frontend:
its like a newssystem (like in the tutorial of the CodeIgniter Userguide) but just for sites. The problem is the URL. when i got a Controller "Sites" it will produces URLs like this:

http://www.mysite.com/sites/about

But i want URLs like this:
http://www.mysite.com/about

i also got other Controllers with a fix URL (each of them got a own Controller):

http://www.mysite.com/contact
http://www.mysite.com/gallery
http://www.mysite.com/news
...

i think i need a function who checks if the controller exist and when not check if the site is in DB... something like that?

i know the _remap() function of CodeIgniter. But it only takes the second segment of the URL. But i want a URL as i described above.

is there any way to make a dynamic controller with such URLs?

Hope u can help me.

And again: sry for my english Smile

Best regards GN
#2

[eluser]gn90at[/eluser]
one problem is now solved. the thing with the dynamic pages...i solved it with the _routes() function.

the only problem i got is the URL:

i want to make this:

http://www.mysite.com/sites/about

to

http://www.mysite.com/about


i cant do it in the routes.php because i got other controllers to like http://www.mysite.com/news.

is there any way to check if a controller exist when yes load the controller when not load my Sites Controller?

my current code if anybody want to see it:

Controller Sites:
Code:
class Sites extends Public_Controller {

public $site;
public $url_segment;

public function _remap($method)
{
  $this->url_segment = $this->uri->segment(2);

  $this->load->model('sites_model');
  $this->site = $this->sites_model->get_site($this->url_segment);

  if($this->site !== FALSE)
  {
   $this->show_site($this->site);
  }
  else
  {
   show_404($this->url_segment);
  }
}

public function show_site($data)
{
  $this->template->set('site', FALSE);
  $this->template->set('site_title', $data['name']);
  $this->template->set('content',$data['content']);
  $this->template->load('public/template','sites/sites_view', $data);
}

}

My Sites_model:
Code:
class Sites_model extends CI_Model {

public function get_site($site_url)
{
  if($site_url != ""){
   $this->db->where('name', $site_url);
   $query = $this->db->get('sites', 1);

   if($query->num_rows() > 0){
    return $query->row_array();
   }
   else
   {
    return FALSE;
   }
  }else{
   return FALSE;
  }
}


}

is is what i got so far Smile

regards
#3

[eluser]InsiteFX[/eluser]
You need to create "routes" within your ./application/config/routes.php file.

i.e.
Code:
$config['default_controller'] = 'front';
$config['about'] = 'front/about';
$config['contact'] = 'front/contact';

CodeIgniter Users Guide - URI Routing
#4

[eluser]gn90at[/eluser]
hi thx for your reply.

yeah i know this solution. the problem is that my pages or in this case "Sites" are not hardcoded controller. it will be generated over an admin-panel. They came from the database. so i dont know wich sites-names will be created. the customer will create them. eg. he creates the sites: about, portfolio & team. (it will be saved in the DB) i dont want to edit the routes.php for each site. this should be done automatically. so i need a function to check if a controller exist...when yes call this controller when not check if a site is in the DB...
and it has to be the first segment of the URL. http://www.mysite.com/portfolio

u know what i mean? :/





Theme © iAndrew 2016 - Forum software by © MyBB