Here is my search function :
class Ads extends Controller
{
public function search($format='velos', $cat='occasion', $location='france', $keyword, $page=1)
{
if($format == 'velos')
{
$query = '`private`=0';
} else
{
$query = '`private`=1';
}
$this->images($query, $cat, $location,'MATCH(title) AGAINST ("'.db::escape($keyword).'" IN BOOLEAN MODE)', $page, '%s/%s/%s/'.$keyword.'/%d/', $row[0], $keyword);
}
}
It’s working fine, when I change the keyword in the URL, everything is okay
But I would like to echo that keyword in the page, I don’t know how ?
I tried
<?php echo $keyword; ?>
But the echo doesn’t return anything. There might be a scope issue, but I’m not sure.
EDIT
Actually the $keyword comes from a search field, but from another class, that’s maybe why I was thinking of a scoping issue
class UserModel extends Model
{
public function search_form()
{
$form = new Form('search_form');
$form->field('keyword', 'text', array
(
'optional' => true
));
if($data = $form->validate())
{
header('Location: '.WEB.sprintf($data['parts_search'].'/'.$data['category_search'].'/'.$data['location_search'].'/'.$data['keyword'].'/1/'));
}
return $form;
}
}
Solution :
It might not be the best solution, but actually the only one I found :
$url = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($url);
$path = $parts['path'];
$keys = explode('/', $path);
echo $keys[4]; // `corresponding to the 4th url word`
I’m having some trouble understanding exaclty what the problem is, but based on your proposed solution, there is an auto-loaded CI class that can do what you’ve proposed.
http://codeigniter.com/user_guide/libraries/uri.html
So, for
http://yoursite.com/format/cat/location/yourKeyword
Hope this helps.