Retrieve Full Name From Database


in my table I have id, firstname, lastname rows. but i need to store both first & last name into name field. pls help me.

I written in model like this…

           public function getFullName() {

                             return $this->first_name . ' ' . $this->last_name;


It’s perfect! Now you call this so:


from where i need to call this one: $this->fullname

Whrere you need name+lastname

i need only name. In name field i need to store fisrt & last name.

Ok. You could create a "complete_name" field and make an UPDATE with CONCAT sql to make name+surname together.

Sorry. i’m not getting. pls tell me how to run in sql

Should be:

UPDATE users SET complete_name = CONCAT(name, ' ', surname)

it’s working. But, it’s not correct process. When i modified like this and login with facebook or google my application is not working.

You should launch this script to normalize your db. Then you should make changes to your code to support name+surname field.


Define variable in model like :

public $full_name;

and then

public function getFullName() {

           $this->full_name=$this->first_name . ' ' . $this->last_name;

                             return $this->full_name;


NOw also i’m not getting fullname into my database.

Do as,

In your model

public $full_name;

public function afterFind(){

 $this->full_name=$this->first_name.' '.$this->last_name;

return parent::afterFind();


Not working like this also. pls help me.

share your code which you are using for testing