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?