Action Controller

My code is this:





public function actionSearch()

	{

		$model=new anagrafe;

		

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

		{

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

			//if($model->save(false))

				$anagra=$_POST['ANAGRA_ID'];

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

		}


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

			'model'=>$model,

		));

	

	}




Is possible to concatenate two fields in the redirect as I did in my function?

I have a need to view cognome + nome…

Does not work … someone tell me what should I change?

Why don’t you use the same function we discussed here ( http://www.yiiframework.com/forum/index.php?/topic/9334-chtmlactivedropdownlist/ )?

Then use $model->cognomeNome instead of $model->COGNOME.’ '.NOME

Otherwise you can use

$cognomeNome = $model->COGNOME.’ '.$model->NOME;

Yes i have just tried…but not work well…

if i pass $ model-> cognomeNome when I load the page in the address bar turns

http://localhost/tirocini/index.php?r=anagrafe/view&id=6550+34537

where the first corresponds to the COGNOME and the second to NAME but not of the same person

i don’t understand…

Try to change approach,

create an id on the table Anagrafe and use this for redirect.

If you use Cognome and Nome as id you will have several problems, like the possibility of omonimous, and a special code for manage people like “De Tommasi” “Dell’Acqua” or “Della Morte”.

Better to use siple ID, an autoincrement is good, CODICE_FISCALE works too (but there are ALWAYS people that don’t remember them own, so can be a problem).

I have always used an ID autoincrement and I never had problem.

Yes i do just it…

before my code is




public function actionSearch()

	

	{

		$model=new anagrafe;

		

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

		{

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

			//if($model->save(false))

				

				$anagra=$_POST['ANAGRA_ID'];

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

		}


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

			'model'=>$model,

		));

	

	}



but the redirect don’t work…

the url is :

http://localhost/tirocini/index.php?r=anagrafe/view&id=

ERROR 404-The requested page does not exist.

Well, is not working because if you do


new anagrafe 

the record is new, and it has’t got any id (because the id is set at the save()).

Your code is really strange. If you popolate the anagrafe with post data, how you can do a redirect? How you can be sure that the user inserted data will let you find exactly one anagrafe, not 0 and not 2?

You should use the search for poplate a datagrid (like gridView) and in this datagrid (that can have 0, 1,5 or 500 result inside) you can create a button that does the require.

When you will create the button you will have a record that comes from the db, and so you will have the id you need for redirect.

Your code has a logical mistake, you cannot rely of data inserted from user for redirect. Create a grid or a list, and do the redirect from this list.

Then with my function I don’t insert any data …

I just do a search … I have a form with a textfile name, address and sex

and after do this I post a redirect to the page with the id

The line with save is commented…otherwise it’s insert a new line