0
votes

So I've inherited a Yii application, I'm trying to get a piece this application to work that does a basic CRUD for management of Scientific factsheets. We're using Yii with Giix

This is the error: "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in /var/www/idtools.org/www/yii/framework/db/ar/CActiveRecord.php on line 58"

The update action is giving us the problems. The update looks like this in the controller:

public function actionUpdate($id) {
    $model = $this->loadModel($id, 'Factsheet');

    if (isset($_POST['Factsheet'])) {
        $model->setAttributes($_POST['Factsheet']);

        if ($model->save()) {
            $this->redirect(array('view', 'id' => $model->factsheetid));
        }
    }

    $this->render('update', array(
            'model' => $model,
            ));
}

The view looks like:

$this->breadcrumbs = array(
    $model->label(2) => array('index'),
    GxHtml::valueEx($model) => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)),
    Yii::t('app', 'Update'),
);

$this->menu = array(
    array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url'=>array('index')),
    array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url'=>array('create')),
    array('label' => Yii::t('app', 'View') . ' ' . $model->label(), 'url'=>array('view', 'id' => GxActiveRecord::extractPkValue($model, true))),
    array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url'=>array('admin')),
);
?>

<h1><?php echo Yii::t('app', 'Update') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model)); ?></h1>

<?php
$this->renderPartial('_form', array(
        'model' => $model));
?>

The model (as generated by Giix) looks like: Yii::import('application.models._base.BaseFactsheet');

class Factsheet extends BaseFactsheet
{
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }
}   

the model extends the base: abstract class BaseFactsheet extends GxActiveRecord {

    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'factsheet';
    }

    public static function label($n = 1) {
        return Yii::t('app', 'Factsheet|Factsheets', $n);
    }

    public static function representingColumn() {
        return 'name';
    }

    public function rules() {
        return array(
            array('name, toolid', 'required'),
            array('weight', 'numerical', 'integerOnly'=>true),
            array('name, toolid', 'length', 'max'=>255),
            array('inputdate', 'safe'),
            array('weight, inputdate', 'default', 'setOnEmpty' => true, 'value' => null),
            array('factsheetid, name, toolid, weight, inputdate', 'safe', 'on'=>'search'),
        );
    }

    public function relations() {
        return array(
            'tool' => array(self::BELONGS_TO, 'Tool', 'toolid'),
            'factsheetcontents' => array(self::HAS_MANY, 'Factsheetcontent', 'factsheetid'),
            'factsheetimages' => array(self::HAS_MANY, 'Factsheetimages', 'factsheetid'),
        );
    }

    public function pivotModels() {
        return array(
        );
    }

    public function attributeLabels() {
        return array(
            'factsheetid' => Yii::t('app', 'Factsheetid'),
            'name' => Yii::t('app', 'Name'),
            'toolid' => null,
            'weight' => Yii::t('app', 'Weight'),
            'inputdate' => Yii::t('app', 'Inputdate'),
            'tool' => null,
            'factsheetcontents' => null,
            'factsheetimages' => null,
        );
    }

    public function search() {
        $criteria = new CDbCriteria;

        $criteria->compare('factsheetid', $this->factsheetid);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('toolid', $this->toolid);
        $criteria->compare('weight', $this->weight);
        $criteria->compare('inputdate', $this->inputdate, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
}

Any idea how to fix my issue? I've given PHP all of my systems memory (memory_init(-1)) and just gotten heap dump errors. I need help, please tell me where to look as I am totally new to Yii.

1

1 Answers

0
votes

You generally get that error as part of your _form partial file. I've often run into it when GxHtml is generating a dropdown menu.

GiiX isn't that efficient at properly pulling all the models out of the database and grabbing the appropriate key / name for your drop-downs. So it's often better to specify the fields you want to retrieve manually.

If you post your _form code (or at least the relevant portions), we can point out the line.