triq
triq

Reputation: 1977

anchor() function in code igniter

I want to use the anchor function to route a view to a controller, however I wanna pass in some variables such as $groupid,$jurisdictionid and append them to the uri segment argument.

For instance,

$groupid=(input by user) $jurisdictionid=(input by user)

anchor ('pagetohit/$groupid/$jurisdictionid')

how do I format this correctly since I want those varaibles to take on the values they are assigned before the anchor function takes them and routes the url.

Upvotes: 1

Views: 8168

Answers (5)

Sumit Kumar Gupta
Sumit Kumar Gupta

Reputation: 2364

It's simple write double quotes (" ") instead of single quotes ('').

When any variable resides double quote then it takes its value not send direct variable.

Example:

anchor("controller/function/$id");

Upvotes: 0

NACHIMUTHU RAMALINGAM
NACHIMUTHU RAMALINGAM

Reputation: 78

It is for passing a single value

 <?php echo anchor("Home_control/add/{$value->id}",'Add Blog',['class'=>'btn btn-info']); ?>

It is for passing a multiple value

 <?php echo anchor("Home_control/add/{$value->id}/{$value->ids}",'Add Blog',['class'=>'btn btn-info']); ?>

or use this

<?php echo anchor("Home_control/add/$value",'Add Blog',['class'=>'btn btn-info']); ?>

1st parameter => Controller name,function name,parameter.

2nd parameter=> Name

3rd parameter=> html attributes

Upvotes: 0

Nana Partykar
Nana Partykar

Reputation: 10548

We Can Pass More Than One Value Using This. For Ex, it will look like this ://...../welcome/deletefiles/3/1

<?php echo anchor("welcome/deletefiles/".$row1->FileNo.'/'.$row1->FileID,
                    '<span class="glyphicon glyphicon-trash" style="color:red;"></span>',
                    array('onclick' => "return confirm('Do you want delete this record')"))?>

Upvotes: 1

patwork
patwork

Reputation: 125

anchor() is internally using site_url(), so you can:

anchor(array('pagetohit', $groupid, $jurisdictionid));

Upvotes: 2

gen_Eric
gen_Eric

Reputation: 227220

Try to use double quotes instead of single quotes.

anchor("pagetohit/$groupid/$jurisdictionid")

Variables inside double quotes will be replaced with their values automatically. PHP Docs

Upvotes: 1

Related Questions