sonorita
sonorita

Reputation: 789

Object of class Createproduct could not be converted to string error in yii

I am new to yii and I am working on creating drop down .I faced the error please suggest me.. Here his my drop down code

    <?php
/* @var $this CreateproductController */
/* @var $model Createproduct */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'createproduct-form',
    'method'=>'post',
    // Please note: When you enable ajax validation, make sure the corresponding
    // controller action is handling ajax validation correctly.
    // There is a call to performAjaxValidation() commented in generated controller code.
    // See class documentation of CActiveForm for details on this.E0E0E0 EFF0F2
    'enableAjaxValidation'=>false,
)); ?>

    <?php echo $form->errorSummary($model); ?>


    <div class="row" style="background-color: #F7F7F7; height:30px;">
        <?php echo $form->labelEx($model,'Product Type'); ?>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
        <?php echo CHtml::dropDownList($model,'pr_name',$model->getTypeOptions() ); ?>
        <?php echo $form->error($model,'pr_type'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'button1')); ?>
    </div>

<?php $this->endWidget(); ?>

</div>

the getTypeOptions() method is has below and constant used inside that method and declared

const CAT_EMPTY=0;
const CAT_PHONE=1;
const CAT_ROUTERS=2;
const CAT_ACCESSORIES=3;
const CAT_SERVICES=4;

public function getTypeOptions()
{
    return array(
    self::CAT_EMPTY=>'Select_Category',
    self::CAT_PHONE=>'Phones',
    self::CAT_ROUTERS=>'Routers',
    self::CAT_ACCESSORIES=>'Accessories',
    self::CAT_SERVICES=>'Services',



    );
}

Help me out..

Upvotes: 1

Views: 2481

Answers (1)

Kumar V
Kumar V

Reputation: 8838

Problem in usage of CHtml::dropDownList you should use like this:

 <?php echo CHtml::dropDownList("model_name[pr_name]",'selected_value',$model->getTypeOptions() ); ?>

Alternatively, you can use $form widget dropDownList function

<?php echo $form->dropDownList($model, 'pr_name',$model->getTypeOptions() ); ?>

Upvotes: 1

Related Questions