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

  • SEARCH
  • Home
  • 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 8319481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:20:30+00:00 2026-06-08T22:20:30+00:00

Q: How can I show the BootDetailView like this. Users name : aa company

  • 0

Q: How can I show the BootDetailView like this.

Users

name : aa
company : test
department : dep1
section : sec1.1
team : team1.1.1

I’ve 2 tbls (department and user)

This is the department tbl structure

department
id | name      | p_id | company_id
1  | dep1      | 0    | 1
2  | dep2      | 0    | 1
3  | sec1.1    | 1    | 1
4  | sec2.1    | 2    | 1
5  | team1.1.1 | 3    | 1
6  | team1.1.2 | 3    | 1
7  | team2.1.1 | 4    | 1

this is the user tbl structure

user
id | name | company_id | team_id
1  | aa   | 1          | 5
2  | bb   | 1          | 5
3  | cc   | 1          | 7
4  | dd   | 1          | 6
5  | ee   | 1          | 6

I added relationship at user model

public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'ranks' => array(self::BELONGS_TO, 'Rank', 'rank_id'),
            'companies' => array(self::BELONGS_TO, 'Company', 'company_id'),
            'departments' => array(self::BELONGS_TO, 'Department', 'team_id'),
        );
    }

this view (CGridView is using at index.php (view))

<?php $this->widget('bootstrap.widgets.BootDetailView', array(
            'data'=>$model,
            'attributes'=>array(
                //array('name'=>'id', 'label'=>'ID'),
                array('name'=>'login_name', 'label'=>'Name'),
                array('name'=>'first_name', 'label'=>'First Name'),
                array('name'=>'last_name', 'label'=>'last Name'),
                array('name'=>'email', 'label'=>'Email'),
                array('name'=>'created', 'label'=>'Created'),
                array('name'=>'ranks.name', 'label'=>'Rank'),
                array('name'=>'companies.name', 'label'=>'Company'),
                array('name'=>'departments.name', 'label'=>'Team'),
            ),
        )); ?>

This is Controller

public function actionView($id)
{
    $model = $this->loadModel($id);
    $sql = 'SELECT id, name FROM rank r WHERE r.id = '. $model->rank_id;
    $rank = Yii::app()->db->createCommand($sql)->queryAll();

    $sql = 'SELECT id, name FROM company c WHERE c.id = '. $model->company_id;
    $company = Yii::app()->db->createCommand($sql)->queryAll();         

    $dst = $this->getDST($model->team_id);

    $this->render('view',array(
        'model'=>$model,
        'rank'=>$rank[0]['name'],
        'company'=>$company[0]['name'],
        'department'=>$dst['department'],
        'section'=>$dst['section'],
        'team'=>$dst['team'],
    ));
}

public function getDST($team_id) // Getting the Department, Section and Team
{
    $records = Department::model()->find('id=:id', array(':id'=>$team_id));
    if($records->p_id == 0 ) {
    $dst['department'] = $model->team_id;
        $dst['section'] = NULL;
        $dst['team'] = NULL;
    } else {
        $records = Department::model()->find('id=:id', array(':id'=>$records->p_id));
        if($records->p_id == 0 ) {
            $dst['department'] = $records->id;
            $dst['section'] = $model->team_id;
            $dst['team'] = NULL;
        } else {
            $dst['section'] = $records->id;
            $dst['team'] = NULL;
            $records = Department::model()->find('id=:id', array(':id'=>$records->p_id));
            if($records->p_id == 0 ) {
                $dst['department'] = $records->id;
                $dst['team'] = $model->team_id;
            }
        }
    }   
    return $dst;
} 
  • 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-08T22:20:33+00:00Added an answer on June 8, 2026 at 10:20 pm

    In Yii relation is simple:

    // User model
    public function relations()
    {
        return array(
            'rank' => array(self::BELONGS_TO, 'Rank', 'rank_id'),
            'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
            'department' => array(self::BELONGS_TO, 'Department', 'team_id'),
        );
    } // User have only one rank, company and department
    
    // Department model
    public function relations()
    {
        return array(
            'parent'   => array(self::BELONGS_TO, 'Department', 'p_id'),
            'children' => array(self::HAS_MANY, 'Department', 'p_id'),
            'company'  => array(self::BELONGS_TO, 'Company', 'company_id'),
            'users'    => array(self::HAS_MANY, 'User', 'team_id'),
        );
    } 
    

    Because : class BootDetailView extends CDetailView
    It is enough:

    // usercontroller
    function actionView($id)
    {
        $this->render('view', array('model' => $this->loadModel($id));
        // or for optimize sql query
        $this->render('view', array('model' => User::model()->with(array('rank', 'company', 'department'))->findByPk($id));
    }
    
    // view.php
    $details = array(
             'login_name',
             'first_name',
             'last_name',
             'email',
             'rank.name',
             'company.name',
         );
    $departments = array();
    $d = $model->department;
    $departments[] = 'department.name';
    $s = 'parent.';
    while ($d->parent != null) {
        $departments[] = 'department.'.$s.'name';
        $s .= 'parent.';
        $d = $d->parent;
    }
    
    $this->widget('bootstrap.widgets.BootDetailView', array(
        'data'=>$model,
        'attributes'=> array_merge($details, $departments),
    )); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I can show the output from this piece
Windows Mobile can show different kind of user notifications, like this: How can I
How can show closeable in the top of the page like stackoverflow new answers.
how i can show the project url in vs as title look like vs
I was wondering how I can show description text. By this I mean, for
Using the Show/Remove Columns context menu option in the Test Results window I can
Basically I am developing an app which can show both the users' current location
I can show a swf into flash simply with this code var request:URLRequest =
In Prototype I can show a loading... image with this code: var myAjax =
With this code I can show an animated gif while the server script is

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.