Rewrite help.

#1
[eluser]adrian.web20[/eluser]
I'm really really tired.
I've been working all day on this. First of all, the User Guide helped me a lot but until a point. Right now, my head doesn't help me a lot.
I seriously need somebody to tell me "Dude, it's wrong because: "
Please help me :| I'm kinda desperate.

I want to make a job seeker website. I've made a db with some job domains categories. This is the URL for testing purposes: http://blt.ath.cx/
I've hit a big bad wall here. As you can see on the website. The rewrite works perfectly... a bit messed up but that's not a problem, for now.
I've manage to go so far but... know I realize I can't do nothing because I don't know how to get the ID from the category, which is very important.

Can somebody please, look over my work and give me some suggestions? I can't continue without your help :|

Thank you

acasa.php
Code:
<?php

class Acasa extends Controller{

    function Acasa()
    {
        parent::Controller();
        
        $this->load->scaffolding('domenii');
    }    

    function index()
    {
        $data['title'] = "http://www.AngajariPitesti.ro/";
        $data['heading'] = "Lista cu domenii";
        $data['query'] = $this->db->get('domenii');
        $this->load->helper('url');
        $this->load->view('acasa_view', $data);
    }
}

?>

oferta.php

Code:
<?php

class Oferta extends Controller{

    function Oferta()
    {
        parent::Controller();
        
        $this->load->scaffolding('domenii');
    }    

    function categorii($categorie)
    {
    $data['query'] = $this->db->get('domenii');
    $this->load->view('domeniu_view', $data);
    }
}

?>

2 views

acasa_view.php
Code:
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1>&lt;?=$heading?&gt;</h1>



&lt;?php foreach($query->result() as $row): ?&gt;

<a >id_domeniu?&gt;-&lt;?=$row->nume_url?&gt;.html">&lt;?=$row->nume_domeniu?&gt;(&lt;?=$row->numar_inscrieri?&gt;)</a><br>

&lt;?php endforeach; ?&gt;

&lt;body&gt;
&lt;/html&gt;

domeniu_view.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
<a href="">Acasa</a>

&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;
&lt;body&gt;
&lt;/html&gt;

.htaccess
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^categorie/(.*)\.html$ oferta/categorii/$1 [C]
RewriteRule ^(.*)$ index.php/$1 [L]

#2
[eluser]kaola[/eluser]
RewriteEngine On
RewriteBase /
RewriteRule ^categorie/(.*)\.html$ /oferta/categorii/$1 [C]
RewriteRule ^(.*)$ /index.php/$1 [L]

#3
[eluser]Rick Jolly[/eluser]
This might work:
Code:
RewriteEngine On
RewriteBase /

RewriteRule ^categorie/(.*)\.html$ index.php/oferta/categorii/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

To keep your .htaccess simpler, you might want to use CI routes instead for these routing exceptions:
http://ellislab.com/codeigniter/user-gui...uting.html

#4
[eluser]tomcode[/eluser]
Two comments:

1. Maybe You have Your reasons to use two controllers, but for what You are doing You need only one controller :
Code:
class Acasa extends Controller{

    function Acasa()
    {
        parent::Controller();
        
        // You shouldn't use scaffolding on a production site
        $this->load->scaffolding('domenii');
    }    

    function index()
    {
        // You should have a better title (for Google)
        $data['title'] = "http://www.AngajariPitesti.ro/";
        $data['heading'] = "Lista cu domenii";
        $data['query'] = $this->db->get('domenii');
        $this->load->helper('url');
        $this->load->view('acasa_view', $data);
    }

    function categorii($categorie)
    {
       $data['query'] = $this->db->get('domenii');
       $this->load->view('domeniu_view', $data);
    }
}

Which changes Your URL's to :
Code:
anchor('acasa/categorii/xx');
2. You can use a config setting if You want to have .html suffixes in Your URL's :
Code:
$config['url_suffix'] = ".html";
which simplifies Your .htaccess :
Code:
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

#5
[eluser]adrian.web20[/eluser]
But the parameter for the categorii() function is something like this: 1-agricultura-pescuit-si-silvicultura.html
How do I use the id (ex: 1) to query the database for detailes ?


Thanks a lot!

#6
[eluser]tomcode[/eluser]
Do You need to pass the whole (1-agricultura-pescuit-si-silvicultura.html), passing only the id (1) does it, too.

If yes though, You could do :
Code:
$cat_parts = explode('-', $categorie);

if(isset($cat_parts[0]) && is_numeric($cat_parts[0]))
{
    $id = $cat_parts[0];
}
else show_404();

#7
[eluser]adrian.web20[/eluser]
Geez :| You are an angel sent from Heaven Smile)

Thank you have much.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.