Nighina t t
Nighina t t

Reputation: 140

how to redirect from view to controller and pass a variable to controller in codeigniter

I have tried to redirect to a function inside a controller from my view in codeigniter. I have used following code

redirect('front/exam_result',$id)

here "front" is my controler,and "exam_result" is my function inside front. and $id is the variable to pass. Is there any mistake in that code ?

Upvotes: 2

Views: 627

Answers (3)

reignsly
reignsly

Reputation: 502

Change comma to dot.

redirect('front/exam_result',$id)

to

redirect('front/exam_result'.$id)

Upvotes: 1

Robin Rai
Robin Rai

Reputation: 392

You can easily redirect to any function/method of controller like this:

redirect(base_url().'Controller/Method');

If you need to pass variable with function/method, you can do this:

redirect(base_url().'Controller/Method/'.$variable);

In your case, this would be solution:

redirect(base_url().'front/exam_result/'.$id);

It is best to use base_url() included rather than direct link like you did.

Upvotes: 1

PHP Geek
PHP Geek

Reputation: 4033

You can pass a variable using codeigniter querystring as follows:

when you are using redirect method :

redirect(base_url().'controller/method/'.<?php echo $variable; ?>);

Upvotes: 0

Related Questions