Working With Mysql And Mvc Practices

Im working with MySQL and form now and have something that I dont understand:


	public function actionCreate()

	{

		$model=new Data;

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

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}

In these codes above, from CRUD generator tool, I have some questions. Can I save to data to database with few attributes? Like the Data model has attributes :a1,a2,a3,a4 and in the form it has input name like: input1, input2, input3, input4.

So can I do like this?:


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

		{

			$model->a1=$_POST['Data']->input1;

			$model->a2=$_POST['Data']->input2;

                        // dont want to use 2 other input, expect a3 and a4 will be default as NULL

			if($model->save())

				

		}

About the MVC practice, I know that controller used to process data and model and send render data to the view. So if I have a function could be reuse in many actions call analyzeData(), should I put it in the controller class or the model class? Im confused because in the guide it said that model must be very large, store data and process data, controller only retrieve data from GET, POST or somethings like this then process it with model and view.

You would want to do it the following way:




$model->a1 = $_POST['Data']['input1'];

$model->a2 = $_POST['Data']['input2'];



As the function name analyzeData() sounds like some business logic you should put it into your model.

Yeah right, this function is about business logic so I will put it into a model class. And thank you for your answer :).