Welcome Guest, Not a member yet? Register   Sign In
F1, F1, F1 please! Routing / remapping
#1

[eluser]Cippo[/eluser]
Hello everyone,

I use CodeIgniter and Doctrine for a custom CMS that I build for my website.

Right now, my uri is something like: http://example.com/home/index/1 ( for the homepage ) and http://example.com/home/index/2 ( for about page - ps: there will be several pages for main navigation ).

I want to ask you if there is a way to access http://example.com/about instead of example.com/home/index/2. In this moment, I have two tables in my database: content and pages and I set up a relationship between them.

Here’s the function for home model:
Code:
class Home_Model extends Doctrine_Record
{

    public function getContentsArray()
    {
        $conts = Doctrine_Query::create()
            ->select('c.body, c.type, c.title, c.page_id')
            ->addSelect('p.id, p.name, p.title')
            ->from('Home_Model c, c.Pages p')
            ->where('p.id = ?', $this->id)
            ->andWhere('p.id = c.id')
            ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
            ->execute();
            
            
        return $conts;
    }

    public function getPagesListArray()
    {
        $pages_list = Doctrine_Query::create()
            ->select('p.name, p.title')
            ->from('Pages_Model p')
            ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
            ->execute();
            
        return $pages_list;
    }
    
    public function setTableDefinition()
    {
        $this->hasColumn('title', 'string', 255);
        $this->hasColumn('body','string', 65535);
        $this->hasColumn('type', 'integer');
        $this->hasColumn('page_id', 'integer');
    }
    
    public function setUp()
    {
        $this->setTableName('content');
        $this->hasOne('Pages_Model as Pages', array(
            'local' => 'page_id',
            'foreign' => 'id'
        ));
    }
}

And my controller:
Code:
public function index($id)
    {
        $home_model = Doctrine::getTable('Home_Model')->find($id);
        
        $vars['conts'] = $home_model->getContentsArray();
        $vars['page_id'] = $home_model['page_id'];
        $vars['title'] = $home_model['Pages']['title'];
        $vars['page_name'] = $home_model['Pages']['name'];
        $name = $home_model['Pages']['name'];
        $vars['content_view'] = 'home';
        // $vars['name'] = $home_model['name'];
        $vars['pages_list'] = $home_model->getPagesListArray();
        $this->load->view('home', $vars);
    }
I don’t want to set each page in routes.php like
Code:
$route[‘about-me’] = “home/index/2”;
. I found a route that looks like
Code:
$route['(:num)'] = 'home/index/$1';
which is a little more convenient and I can access the pages using: http://example.com/4

BUT what I want is to replace the id with the 'slug' that I have created in my database Pages table.

PS: I've been looking over the forum all day long but couldn't find that something. I've got some headaches so I'm asking for some help. Thanks


Messages In This Thread
F1, F1, F1 please! Routing / remapping - by El Forum - 03-22-2010, 03:21 PM
F1, F1, F1 please! Routing / remapping - by El Forum - 03-22-2010, 03:43 PM
F1, F1, F1 please! Routing / remapping - by El Forum - 03-23-2010, 03:32 AM
F1, F1, F1 please! Routing / remapping - by El Forum - 03-23-2010, 07:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB