Trying to solve:
Fatal error: Call to a member function hasErrors() on a non-object in /var/www/sega/yii/framework/web/helpers/CHtml.php on line 1625
Form code:
<?php echo CHtml::beginForm(); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php //echo CHtml::errorSummary($model); ?>
<?php /*
<div class="row">
<?php echo CHtml::activeLabelEx($model,'market_id'); ?>
<?php echo CHtml::activeTextField($model,'market_id'); ?>
<?php echo CHtml::error($model,'market_id'); ?>
</div>
*/?>
<?php for ($i=1; $i<=$number_of_outcomes; $i++)
{
?>
<div class="row">
<?php //echo CHtml::activeLabelEx($model,"name"); ?> <?php echo $i;?>
<?php echo CHtml::activeTextField($model,"name[$i]",array('size'=>60,'maxlength'=>255)); ?>
<?php echo CHtml::error($model,"name[$i]"); ?>
</div>
<?php
}
?>
<input type="hidden" name="market_id" value="<?php echo $_GET['market_id']?>" />
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php echo CHtml::endForm(); ?>
I’ve also tried
[$i]name
Rules in model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('market_id', 'required'),
array('market_id', 'numerical', 'integerOnly'=>true),
// array('name', 'length', 'max'=>255),
);
}
Controller action:
public function actionBatchCreate()
{
// retrieve items to be updated in a batch mode
// assuming each item is of model class 'Item'
//$items=$this->getItemsToUpdate();
//$items = Assets::model()->findAll();
$assets_array = array();
if(isset($_POST['assets']))
{
$valid=true;
foreach($_POST['assets'] as $i=>$item)
{
// if(isset($_POST['Item'][$i]))
$asset_obj = new assets;
$asset_obj->attributes=$_POST['assets'][$i];
$assets_array[] = $asset_obj;
$valid=$valid && $asset_obj->validate();
}
if($valid)
{
foreach($assets_array as $v)
{
$v -> save();
}
$this->redirect(array('market/trade','id'=>$_POST['market_id']));
}
}
// displays the view to collect tabular input
$this->render('batchCreate',array('assets'=>$assets_array));
}