pass variable to view

should I switch to a view of the variables, i have a model


namespace app\models;

use yii\base\Model;

class EntryForm extends Model


public $name;

public $email;

public function rules()


return [

[['name', 'email'], 'required'],

['email', 'email'],





$model = new EntryForm;

if ($model->load(Yii::$app->request->post()) && $model->validate()) {

// valid data received in $model

//return   $this->redirect(['mappa']);

// do something meaningful here about $model ...

return $this->render('entry-confirm', ['model' => $model]);

} else {

// either the page is initially displayed or there is some validation error

return $this->render('entry', ['model' => $model]);



view form


use yii\helpers\Html;

use yii\widgets\ActiveForm;


<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'name') ?>

<?= $form->field($model, 'email') ?>

<div class="form-group">

<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>


<?php ActiveForm::end(); ?>

I would like to send a variable to a view of another controller

 echo $newvariable;

// send with button or link of the form

Hi synapse,

It is very simple

$this->render('//another_view_folder/another_view_file_name',['yourvar' => $yourvar])

So your data flow should be like this

Current Controller -> View -> View of another Controller view folder’s view

You should pass the variable from current controller to current view at your action.

Then you can pass to another controller view folder’s view.

I hope this has helped u.