How to recover only 1 URL value with Codeigniter?

Asked

Viewed 213 times

2

I’m passing two parameters http://localhost/topsamp-ci/votar/4-Slug-de-algo

 public function votar($id) {
    echo $id;
    die;
 }

And it returns me 4-Lug-de-something. I wanted to just recover the ID but displaying in the url the two parameters, as I do this?

My route is like this:

$route['votar/(:any)'] = 'Home/votar/$1';

Voting button

<a href="<?= base_url("votar/{$row->id}-{$row->slug}"); ?>" class="btn btn-vote">VOTAR</a>

1 answer

2


The parameter delimiting is the bar /

You need to assemble the link like this:

<a href="<?= base_url("votar/{$row->id}/{$row->slug}"); ?>" class="btn btn-vote">VOTAR</a>

Change the stroke - by the bar /

Stay like this: http://localhost/topsamp-ci/votar/4/Slug-de-algo

If you want to keep it the other way, you will get it all together, then you have to slice the string.

  • It worked man, I’ll leave anyway for safety thank you!

  • I was going to do that, but I was making a mistake I had to wait 7 minutes haha, vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.