jlocker
jlocker

Reputation: 1488

codeigniter how to pass base_url() from controller

I want to pass the base_url() from controller to view..Without echoing it in the view it self, I want to pass it in the array as below,

$data= array(
'url'=> "<a href='".base_url()."/method/parm'>click</a>"
);

how can i do this??

Thanks!

Upvotes: 2

Views: 4947

Answers (3)

Josua M C
Josua M C

Reputation: 3158

on your controller:

$data['base_url'] = base_url();
$this->load->view('myview',$data);

on your view

just type

<a href="<?php echo $base_url; ?>/method/parm">click</a>

Upvotes: 1

KTAnj
KTAnj

Reputation: 1356

Open /application/config/config.php

$config['base_url'] = 'your base url'; // Ex:'http://localhost/testproject/'

Upvotes: 1

Frenkey
Frenkey

Reputation: 114

you'll need to pass your $data variable

$data['sample'] = "<a href='".base_url()."/method/parm'>click</a>";
$this->load->view('myview',$data);

then in your view just echo the index you want

View example

<div>
<?php echo $sample; ?>
</div>

Hope this helps

Upvotes: 3

Related Questions