Create a form

Hi, i have a problem, hope anyone can help me.

i want create a 2 form (Acquisition and Item).

In Acquisition form, have item form. but when i click item form, i will get "Error 404

1:The requested project does not exist."

ItemController.php


private $_acquisition = null;


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


	/**

	 * @return array action filters

	 */

	protected function loadProject($acquisition) {


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

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

            {

                $this->_acquisition=Acquisition::model()->findbyPk($acquisition);

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

                        {

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

                        }


                }

            return $this->_acquisition;

         }


        /**

        * In-class defined filter method, configured for use in the above

        filters() method

        * It is called before the actionCreate() action method is run in

        order to ensure a proper project context

        */


         public function filterProjectContext($filterChain)

        {

        //set the project identifier based on either the GET or POST input

        //request variables, since we allow both types for our actions

            $acquisitionId = null;


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

            $acquisition = $_GET['pid'];


            else


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


                    $acquisitionId = $_POST['pid'];

                    $this->loadProject($acquisitionId);

                    //complete the running of other filters and execute the requested action

                    $filterChain->run();

        }


public function actionCreate()

	{

		$model=new Item;

                $model->acquisition = $this->_acquisition->id;

		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}



Acquisition/view.php


 array('label'=>'Create Item', 'url'=>array('item/create', 'pid'=>$model->id)),

I think Item form dont receive ID from Acquisition form. What is wrong with my code?

at url http://localhost/muziumtest2/index.php/item/create?pid=2,

i see error 404.

Acquisition model.


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(

			'typeAcquired0' => array(self::BELONGS_TO, 'AcType', 'type_acquired'),

			'items' => array(self::HAS_MANY, 'Item', 'acquisition'),

		);

	}



foreign key is acquisition. acquisition is ID. It should send to Item form after submit Acquisition form. But it’s not work.

in itemcontroller.php


protected function loadProject($acquisition) {


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

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

            {

                $this->_acquisition=Acquisition::model()->findbyPk($acquisition);

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

                        {

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

                        }


                }

            return $this->_acquisition;

         }

At $this->_acquisition=Acquisition::model()->findbyPk($acquisition);

i replace this code to $this->_acquisition=Acquisition::model()->findbyPk(1);

it will view item form.

so problem with $acquisition. Hope some one can help me solve my doubt.

it’s work now.

hi Ann, can you share how you solve this? i have the same problem