1

I need to add a textfield which does not belong to the model. So I've added the following code in the form

<?= Html::textInput("totaldays", $value) ?>

Please tell me how to declare this variable or how can I resolve this. I've tried adding

public $value;

in the model. But the error remains. Please help.

Controller

public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
            'totaldays' => $value,
        ]);
    }

view.php

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model frontend\modules\salary\models\Salary */
//@var $model yii\base\Model
//@var $totaldays any

$this->title = $model->s_id;
$this->params['breadcrumbs'][] = ['label' => 'Salaries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="salary-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Update', ['update', 'id' => $model->s_id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('Delete', ['delete', 'id' => $model->s_id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            's_id',
            's_date',
            's_period',
            's_empid',
            's_empname',
            's_workingdays',
            's_leave',
            's_holiday',
            's_wageperday',
            's_totalwage',
            's_ovthour',
            's_ovtrateperhour',
            's_ovtamount',
            's_tiffinworkingday',
            's_tiffinrateperday',
            's_wdtiffinamount',
            's_sundayworked',
            's_sundayrate',
            's_sundaytiffinamount',
            's_nightcount',
            's_nightallrate',
            's_nightallowance',
            's_convday',
            's_convrate',
            's_conveyanceamount',
            's_tiffinovtcount',
            's_tiffinovtrate',
            's_tiffinovtamount',
            's_incentivecount',
            's_incentiverate',
            's_incentive',
            's_totalearning',
            's_epf',
            's_esi',
            's_ptax',
            's_takehome',
        ],
    ]) ?>

</div>

_form.php

<div class="col-xs-4 col-sm-4 col-lg-4">
                <?= Html::textInput("totaldays", $value) ?>
                </div>

error -

Undefined variable: value
1
  • can you tell exactly how you are using `_form.php. I can not find in you upper code use or include of this file. Commented Jun 24, 2016 at 6:08

1 Answer 1

3

Your Contoller Code should like : -

public function actionCreate()
{
  ......your rest of code.........

  $value = 'my Value';
  return $this->render('create', [
            'model' => $model,
            'value' => $value
        ]);
}

public function actionUpdate($id)
{
    ......your rest of code.........

  $value = 'my Value';
  return $this->render('create', [
        'model' => $model,
        'value' => $value
        ]);
}

Then in create.php and update.php Change :-

<?= $this->render('_form', [
    'model' => $model,
    'value' => $value
]) ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.