1

I am saving a form by using submit button. On creating it I am redirecting it to another view. In this view I am passing the id of the model and then from that model I am setting the variables that I can use further.

public function actionViewpdf($id)
{
     $model=$this->findModel($id);
    /*print_r($model);
    exit();*/
    $id = $model->id;
    $created_by = $model->created_by;
    $issuer = $model->issuer;
    $store = $model->store_id;
    $admin = $model->admin_incharge;
    $pm = $model->project_manager;


    $session = Yii::$app->session;
    $session ->set('id',$id);

    $session = Yii::$app->session;
    $session ->set('created_by', $created_by);

    $session = Yii::$app->session;
    $session ->set('user',$issuer);

    $session = Yii::$app->session;
    $session ->set('store', $store);

    $session = Yii::$app->session;
    $session->set('admin',$admin);

    $session = Yii::$app->session;
    $session ->set('pm',$pm);

}

In my view I am showing these variables

<h5>OGP Serial# : <?php echo Yii::$app->session['id']; ?></h5><br/>
        <h5>Created By: <?php echo Yii::$app->session['created_by']; ?></h5><br/>
        <h5>Issued To: <?php echo Yii::$app->session['user']; ?></h5><br/>
        <h5>Store: <?php echo Yii::$app->session['store']; ?></h5><br/>
        <h5>Admin In-Charge: <?php echo Yii::$app->session['admin']; ?></h5><br/>
        <h5>Project Manager: <?php echo Yii::$app->session['pm']; ?></h5><br/>

The output I am getting is

OGP Serial# : 28


Created By: 12


Issued To: 88


Store: 10


Admin In-Charge: Faisal


Project Manager: Ali

Now in Created By, Store and Issued to I want to show the name instead of the ID

I have searched for it but couldn't find the answers

Any help would be highly appreciated.

Faisal Qayyum
  • 132
  • 13

1 Answers1

0

you could use something like:

echo User::findById(Yii::$app->session['created_by'])->name

another thing that could be useful is create relations in your model object's class and pass the model to the view, making it available as

$model->createdBy->name

SmartCoder
  • 413
  • 2
  • 13