Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:16:33+00:00 2026-06-17T08:16:33+00:00

My User Model have 3 Status options (Active, Deleted, Blocked). When seeing it in

  • 0

My User Model have 3 Status options (Active, Deleted, Blocked).
When seeing it in the view it shows as numbers 1, 2 or 3. What I can do to show it by the status name?

Model.php

const STATUS_ACTIVE = 1;
const STATUS_DELETED = 2;
const STATUS_BLOCKED = 3;

Controller.php

public function actionAdmin()
{
    $model=new Users('search');
    $model->unsetAttributes();  // clear any default values
    if(isset($_GET['Users']))
        $model->attributes=$_GET['Users'];

    $this->render('admin',array(
        'model'=>$model,
    ));
}

View.php

<?php $this->widget('bootstrap.widgets.TbGridView',array(
    'type'=>'striped bordered condensed',
    'id'=>'users-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'name',
        'status', // Show 1,2 or 3. I want to get the status name.
    ),
)); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:16:34+00:00Added an answer on June 17, 2026 at 8:16 am

    Create a new method in your User model called getStatusName that returns the status name. Here is one possible way of doing it:

    public function getStatusName()
    {
        switch($this->status)
        {
            case self::STATUS_ACTIVE:
                return 'Active';
                break;
    
            case self::STATUS_DELETED:
                return 'Deleted';
                break;
    
            case self::STATUS_BLOCKED:
                return 'Blocked';
                break;
    
            default:
                return 'Unknown';
                break;
        }
    
    }
    

    Then in your CGridView, do this:

    <?php $this->widget('bootstrap.widgets.TbGridView',array(
        'type'=>'striped bordered condensed',
        'id'=>'users-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
            'name',
            'statusName' // And let Yii do its magic OR be explicit
            array('name' => 'status', 'type' => 'text', 'value' => '$data->statusName'),
        ),
    )); ?>
    

    Note: if you used the short version on the column configuration, you should add statusName to your attributeLabels array

    //model.php
    public function attributeLabels(){
      return array(
        //Other labels
        'statusName' => 'status',
      )
    }
    

    This way you can also use the same attribute in other places, and let it behave like a normal attribute (only that it is read-only).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a typical User model (username, password, name, etc). I want to allow
Let's say I have User model and Post model. Post model contains field user_id
I have a model that has a ForeignKey to the built-in user model in
Hello I have a user model and a ratings model. Whenever a new user
I have a simple User model which is associated to many Town objects using
I have one model User and will be creating another one Category . Both
I have defined a User model and added a featured field to it: class
I have a User model that has many posts. Im trying to render the
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.