Reputation: 89
I have a function in my controller that retrieves User name
here:
public function getUserName(){
$user_id = $this->session->userdata('user_id');
return $this->user_model->sban_name($user_id);
}
Now, what I want is to put it directly inside an HTML tag like this,
<a href="#"><?php echo getUserName();?></a>
But, it's not working. Is there any other way to do it?
Upvotes: 0
Views: 1324
Reputation: 7725
You need to pass the username
to your view via the controller. You can't access controller functions in your view. So in the controller that loads the view, do something like this:
$data['username'] = $this->getUserName();
$this->load->view('view_name',$data);
Then in your view you can simply echo
the username
:
<a href="#"><?php echo $username ?></a>
Upvotes: 2