Question

I'am having ledger as a model which have a field name account_type.It holds the value credit and debit. If i give credit then it should goes to payment page. If i give debit then it should goes to receipt page. For this i need to give a condition in my actionPayment and actionReceipt.

This is my actionPayment code.

public function actionPayment()
    {
        $criteria = new CDbCriteria();
        $criteria->params=(array(':account_type'=>'credit'));
        $dataProvider=new CActiveDataProvider('Payments');
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    )); 
    }

I want to display all the rows in payment page those which are given credit. I'am a beginner to yii. can anyone please help me to solve my problem? This is my view file.

 <tr>
<td>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
</td><td>
<?php echo CHtml::encode($data->account_type); ?>
<br />
</td><td>
<?php echo CHtml::encode($data->refer_no); ?>
    <br /></td>
<td>
<?php echo CHtml::encode($data->bill_no); ?>
<br />
</td>
<?php echo CHtml::encode($data->comments); ?>
    <br /></td>
<td>
<?php echo CHtml::encode($data->balance); ?>
    <br /></td>
<td>
<?php echo CHtml::encode($data->transaction_date); ?>
<br />
</td>

This is my form page errorSummary($model); ?>

<div class="form-group">
    <?php echo $form->labelEx($model,'id',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'id', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?></div>
    <?php echo $form->error($model,'id'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'account_type',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'account_type', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?></div>
    <?php echo $form->error($model,'account_type'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'refer_no',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'refer_no', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?></div>
    <?php echo $form->error($model,'refer_no'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'bill_no',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'bill_no', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?>
        </div>
    <?php echo $form->error($model,'bill_no'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'comments',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'comments', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?>
        </div>
    <?php echo $form->error($model,'comments'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'balance',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'balance', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?>
        </div>
    <?php echo $form->error($model,'balance'); ?>
</div>

<div class="form-group">
    <?php echo $form->labelEx($model,'transaction_date',array("class" => "col-sm-2 control-label")); ?>
        <div class="col-sm-10">
    <?php echo $form->textField($model,'transaction_date', array('class' => 'form-control', 'size' => 45, 'maxlength' => 45)); ?>
        </div>
    <?php echo $form->error($model,'transaction_date'); ?>
</div>

<div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array("class"=>"btn btn-success")); ?>
        </div>"
</div>
Was it helpful?

Solution

try this:

public function actionPayment()
{
    $criteria = new CDbCriteria();
    $criteria->condition = "account_type = :account_type";
    $criteria->params=(array(':account_type'=>'credit'));
    $dataProvider=new CActiveDataProvider('Payments',array(
        'criteria'=>$criteria,
    ));
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    )); 
}

OTHER TIPS

You can also use this

$criteria->compare('account_type', 'credit');

Against

$criteria->condition = "account_type = :account_type";
$criteria->params=(array(':account_type'=>'credit'));

Full example:

criteria = new CDbCriteria();
$criteria->compare('account_type', 'credit');
$dataProvider=new CActiveDataProvider('Payments',array(
    'criteria'=>$criteria,
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top