Search form

This is my code…

public function actionSearch()



		$model=new anagrafe;





				$cognome = strtoupper( $_POST['cognome']);

				$nome= strtoupper($_POST['nome']);

				$connection=new CDbConnection('oci:dbname=//oracledb:1521/oraprod','ora02','oracle');


				$command=$connection->createCommand("SELECT ANAGRA_ID FROM ANAGRAFE WHERE NOME='$nome' AND COGNOME='$cognome'");



				 foreach($reader as $row) 


						$ID= $row['ANAGRA_ID'];









I would add an if cycle to filter the data as if I have two people with the same name … I see them and make the user choose which to display…

Can you help me???

Take a look at the documentation about CActiveRecord, you can use the more effectively and avoid to write query.

You can do like that:

public function actionSearch()


	$model=new anagrafe;







		if ($dataProvider->totalItemCount==1)











In the view ‘search’ you can add the code for display the found users.

This code is really very similar to the code of the actionAdmin created by crud.

If you generated the AR of anagra with gii (or Yii shell) you have the method search that create the DataProvider.

Read the documentation about CActiveDataProvider and about CActiveRecord for understand how AR works.

Where do you have take this code???

I have generated with shell model class and controller but there isn’t this code?

I can use this code for my problem?

I created a search form to filter the data in a table of members before exporting the data. I currently facing a strange problem with the advanced search form. He loses his values ​​and I does not understand why?

#view form fields :



#Controler :


     * Méthode pour exporter les données de la table membres 

     * dans un fichier excel



    public function actionExport(){

	$model=new Tblmembres('search');

	$model->unsetAttributes();  // clear any default values



                    echo "<pre>";


                    echo "</pre>";



            // Afficher le formulaire pour filtrer




#Controler output after submiting the form… some fields are empty…



[idfaculte] => 1

[idservice] => 1

[idpavillon] => 48

[idstatutemploye] => 1

[idcategoriedonnateur] => 

[lstassignation] => 

[nom] => 

[prenom] => 

[nomusager] => Nomdusager

[type_usager] => 

[no_employe] => 

[local] => 

[syndicat] => syndicat

[email] => 

[telephone] => 4196666666

[connexion] => Desactivee

[date_embauche] => 

[date_inscription] => 2013/11/11

[idmembres] => 


If you have an idea or suggestion why values ​​disappear.

Thank you!