Undefined Property / Variable while in localhost

Hi,

I recently inherited a project from a developer who has left and it was my job to update yiibooster on the project and make sure the front end all connected together and worked properly.

Noticing from the start though that before I changed anything, that the project brought up undefined variables on 3 occasions (that I’ve notice) that did not work while running the project in XAMPP.

Interestingly enough though, it DOES work in the server. The database entries all seem the same and the code is the same.

What I’ve tried already :

Disabling notice errors.

Isset variables

turning off debug mode

Removing functionality (it’s spaghetti’d elsewhere, and I don’t have the experience to rebuild the entire functionality in the time span)

I presume that fixing one of the undefined variables will help me with the other ones. The variable I am currently looking at delegate_select_event_group which belongs to the property EventGroups. This is going through the options.php model rather than with the rest of the form, but it works on the server.

The error I get when debug is turned on is" Property "EventGroups.delegates_select_event_group " is not defined."

If I’ve missed anything that looks like it should be there but this seems to be all the relevant code.

First up, the view file for the form.

protected/modules/admin/views/eventGroups/_form.php




$form = $this->beginWidget('booster.widgets.TbActiveForm', array(

    'id' => 'event-groups-form',

    'enableAjaxValidation' => true,

        ));

?>


<?php echo $form->switchGroup($model,  'delegates_select_event_group' , array('class' => 'col-md-6')); ?>




<div class="form-actions">

    <?php

    $this->widget('booster.widgets.TbButton', array(

        'buttonType' => 'submit',

        'context' => 'primary',

        'label' => $model->isNewRecord ? 'Create' : 'Save',

    ));

    ?>

</div>

the model

protected/models/EventGroups.php


class EventGroups extends SelectionBasedActiveRecord {


    public $selection_types;

    public $label_type = 'Event';

    public $set_session_dates = false;

    public $set_sales_dates = true;

    // Varible for Options

    public $delegates_select_event_group;




    /**

     * Returns the static model of the specified AR class.

     * @param string $className active record class name.

     * @return EventGroups the static model class

     */

    public static function model($className = __CLASS__) {

        return parent::model($className);

    }


    /**

     * @return string the associated database table name

     */

    public function tableName() {

        return '{{event_groups}}';

    }


    /**

     * @return array validation rules for model attributes.

     */

    public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

            // array('name, description, guest_invites_per_user ', 'required'),

            array('name, description, guest_invites_per_user, delegates_select_event_group ', 'required'),

            array('guest_invites_per_user', 'numerical', 'integerOnly' => true),

            array('name', 'unique', 'message' => Yii::t("EventGroups.name", "This Event Group Name is already being used, please choose another.")),

            array('name', 'length', 'max' => 128),

            array('description', 'length', 'max' => 750),

            array('guest_invites_per_user', 'length', 'max' => 2),

            array('sales_start_time, sales_end_time', 'safe'),

            // The following rule is used by search().

            // Please remove those attributes that should not be searched.

            array('id, name, selection_logic_group, description', 'safe', 'on' => 'search'),

        );

    }


 public static function getOptions() {

        return CHtml::listData(EventGroups::model()->findAll(), 'id', 'name');

    }

protected/models/Options.php


public static function model($className = __CLASS__) {

        return parent::model($className);

    }


    /**

     * @return string the associated database table name

     */

    public function tableName() {

        return '{{options}}';

    }


 const KEY_DELEGATES_SELECT_EVENT_GROUP = 'delegates_select_event_group';


    public static function isDelegatesSelectEventGroup() {

        return self::getValue(self::KEY_DELEGATES_SELECT_EVENT_GROUP, false);

    }


    public static function setDelegatesSelectEventGroup($value) {

        return self::setValue(self::KEY_DELEGATES_SELECT_EVENT_GROUP, $value);

    }


    const KEY_DEFAULT_EVENT_GROUP_ID = 'default_event_group_id';


    public static function getDefaultEventGroupID() {

        $model = EventGroups::model()->find();

        if ($model === null) {

            return self::getValue(self::KEY_DEFAULT_EVENT_GROUP_ID, 1);

        } else {

            return self::getValue(self::KEY_DEFAULT_EVENT_GROUP_ID, $model->id);

        }

    }


    public static function setDefaultEventGroupID($value) {

        return self::setValue(self::KEY_DEFAULT_EVENT_GROUP_ID, $value);

    }

The Controller (first one, not sure what it is taking)

protected/modules/admin/controllers/EventGroupsControllers.php


public function actionView($id) {

        $this->render('view', array(

            'model' => $this->loadModel($id),

        ));

    }


    /**

     * Creates a new model.

     * If creation is successful, the browser will be redirected to the 'view' page.

     */

    public function actionCreate() {

        $model = new EventGroups;


        // Uncomment the following line if AJAX validation is needed

        $this->performAjaxValidation($model);


        if (isset($_POST['EventGroups'])) {

            $model->attributes = $_POST['EventGroups'];


            if ($model->validate()) {

                // Valid Save 

                $model->save(false);

                $this->redirect(array('event/create'));

            }

        }


        $this->render('create', array(

            'model' => $model,

        ));

    }


    public function actionajax() {

        return true;

    }


public function actionUpdate($id) {

        $model = $this->loadModel($id);

        $model->delegates_select_event_group = Options::isDelegatesSelectEventGroup();


        // Uncomment the following line if AJAX validation is needed

        $this->performAjaxValidation($model);


        if (isset($_POST['EventGroups'])) {

            $model->attributes = $_POST['EventGroups'];

            if ($model->save()) {

                Options::setDelegatesSelectEventGroup($model->delegates_select_event_group);


                $this->redirect(array('view', 'id' => $model->id));

            }

        }


        $this->render('update', array(

            'model' => $model,

        ));

    }


public function actionIndex() {

        $dataProvider = new CActiveDataProvider('EventGroups');

        $this->render('index', array(

            'dataProvider' => $dataProvider,

        ));

    }


    /**

     * Manages all models.

     */

    public function actionAdmin() {

        $model = new EventGroups('search');

        $model->unsetAttributes();  // clear any default values

        if (isset($_GET['EventGroups']))

            $model->attributes = $_GET['EventGroups'];


        $this->render('admin', array(

            'model' => $model,

        ));

    }

 protected function performAjaxValidation($model) {

        if (isset($_POST['ajax']) && $_POST['ajax'] === 'event-groups-form') {

            echo CActiveForm::validate($model);

            Yii::app()->end();

        }

    }


    public static function getDefaultEventGroupID() {

        $model = EventGroups::model()->find();

        if ($model === null) {

            return self::getValue(self::KEY_DEFAULT_EVENT_GROUP_ID, 1);

        } else {

            return self::getValue(self::KEY_DEFAULT_EVENT_GROUP_ID, $model->id);

        }

    }



That is weird code. Using find() without parameters. I wonder what it will retrieve. It is very probable that it will retrieve something different in production versus test.

Also check the code in the static function getValue() ?

Hi,

the getValue function seems to be this, which is located in the protected/modules/appmanager/components/entity/AmOption.php


   public function getValue()

    {

        if (null === $this->value) {

            return $this->getDefault();

        }

        return $this->value;

    }

Edit.2 never mind, found the getvalue in the options.php


  public static function getValue($key, $defaultValue = null) {

        // Null check params

        if (isset($key)) {

            // Load Model

            $option = self::loadModelByKey($key);

            // If $option is null no key exists with that name.

            if (isset($option)) {

                return $option->option_value;

            } else {

                if (isset($defaultValue)) {

                    $option = new Options();

                    $option->option_name = $key;

                    $option->option_value = $defaultValue;


                    $option->save();

                    return $option->option_value;

                }

            }

        }

        return null;

    }




Regarding the find parameters, do you have any guess in what I Should be putting into the parameters or any idea how it works? I presume without parameters it’ll just look at the entirety of the model but I can take a guess and say that’s completely wrong!

Edit. I tried to put the variable inside the find and the function declaration but it is still known as undefined.

public static function getDefaultEventGroupID() {

    &#036;model = EventGroups::model()-&gt;find('delegate_select_event_group');

Doesn’t work.