drop down menu problem

hi,

i got a problem


Fatal error: Call to a member function getAcType() on a non-object in C:\xampp\htdocs\muziumtest\protected\views\acquisition\_form.php on line 20

i want make a drop down menu list that call form table ac_type and view at acquisition form

1-bequest,

2-gift,

3-purchases.

_form.php (view/Acquisition/_form.php)


<div class="row">

		<?php echo $form->labelEx($model,'type_acquired'); ?>

		<?php echo $form->dropDownList($model,'type_acquired', $this->getAC()->getAcType()); ?>

		<?php echo $form->error($model,'type_acquired'); ?>

	</div>


[/code]


[code]class AcType extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return AcType 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 'tbl_ac_type';

	}


	/**

	 * @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('ac_type', 'length', 'max'=>45),

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

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

			array('id, ac_type', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'acquisitions' => array(self::HAS_MANY, 'Acquisition', 'type_acquired'),

                       

                  

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'ac_type' => 'Ac Type',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('ac_type',$this->ac_type,true);


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}

public function getAcType ()

        {

           $acTypeArray = CHtml::listData ($this->acquisitions, 'id', 'ac_type');

           return $acTypeArray;


        }

       

}


<?php


class AcquisitionController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */


    private $_actype = null;


    

	public $layout='//layouts/column2';




         protected function loadProject($id) {


            //if the project property is null, create it based on input id

            if($this->_actype===null)

            {

                $this->_actype=AcType::model()->findbyPk($id);

                    if($this->_actype===null)

                        {

                        throw new CHttpException(404,'The requested project does not exist.');

                        }


                }

            return $this->_actype;

         }


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	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 Acquisition;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Acquisition']))

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}


	/**

	 * Updates a particular model.

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

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

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


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Acquisition']))

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'index' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		if(Yii::app()->request->isPostRequest)

		{

			// we only allow deletion via POST request

			$this->loadModel($id)->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('Acquisition');

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

			'dataProvider'=>$dataProvider,

		));

.

.

.

.

.

.

.

.


         public function getAC()

{

            return $this->_actype;

}

}






Please help me. I’m stuck. Thank you very much.

From where u r calling loadProject

In the context of a view, $this is the controller.

The model is in model, so use


$this->getAC()->getAcType());

i already define it in /view/acquisition/_form…


<div class="row">

                <?php echo $form->labelEx($model,'type_acquired'); ?>

                <?php echo $form->dropDownList($model,'type_acquired', $this->getAC()->getAcType()); ?>

                <?php echo $form->error($model,'type_acquired'); ?>

        </div>

but still got the same problem.

from acquisitioncontroller.php

Thank you. It’s done. Now, I can view the drop down menu from table. I refer here.


public function getAcType ()

        {

         

           $acTypeArray = CHtml::listData (AcType::model()->findAll(), 'id','ac_type');

           return $acTypeArray;


        }