Yii Framework Forum: CHtml::activeDropDownList and Button... - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CHtml::activeDropDownList and Button... Rate Topic: -----

#1 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 07 June 2010 - 03:17 AM

this is my code:
<?php 
if (!isset($_POST['prova2']))
{
	$grandezza=count($_GET['id']);
}
else
{
	$grandezza=0;
	$_GET['id']=$_POST['prova2'];
}
if ($grandezza >1 )
{
	echo CHtml::beginForm('','post',array("name"=>"prova","id"=>"prova"));
	$connection = Yii::app()->db;
	for ($i=0; $i<$grandezza; $i++){
	$command = "SELECT ANAGRA_ID,COGNOME,NOME,CODICE_FISCALE,DATA_NASCITA  FROM ANAGRAFE WHERE   ANAGRA_ID=".$_GET['id'][$i]."";
	$reader=$connection->createCommand($command)->query();
	foreach($reader as $row) 
   	{
   		$RIGA["ID"]= $row['ANAGRA_ID'];
   		$RIGA['VALORE']=$row['COGNOME'].' '.$row['NOME'].' '.$row['CODICE_FISCALE'].' '.$row['DATA_NASCITA'];
   		$docente[$i]= $RIGA;
   		
   	}
	}
	echo '<div class="row" align="center">
	<p align="center">La ricerca ha generato il seguente risultato:</p>';
		 //echo CHtml::label('Risultati',$lab); 
		 echo '<br></br>';
		 echo CHtml::listBox('prova2','ANAGRA_ID',CHtml::listData($docente,'ID','VALORE'));
		 //echo CHtml::error($model,'NOME'); 
	echo '</div><br></br><br></br><br></br>';
	
	
	
	
	<?php 
if (!isset($_POST['prova2']))
{
	$grandezza=count($_GET['id']);
}
else
{
	$grandezza=0;
	$_GET['id']=$_POST['prova2'];
}



if ($grandezza >1 )
{
	echo CHtml::beginForm('','post',array("name"=>"prova","id"=>"prova"));
	$connection = Yii::app()->db;
	for ($i=0; $i<$grandezza; $i++){
	$command = "SELECT ANAGRA_ID,COGNOME,NOME,CODICE_FISCALE,DATA_NASCITA  FROM ANAGRAFE WHERE ANAGRA_ID=".$_GET['id'][$i]."";
	$reader=$connection->createCommand($command)->query();
	foreach($reader as $row) 
   	{
   		$RIGA["ID"]= $row['ANAGRA_ID'];
   		$RIGA['VALORE']=$row['COGNOME'].' '.$row['NOME'].' '.$row['CODICE_FISCALE'].' '.$row['DATA_NASCITA'];
   		$docente[$i]= $RIGA;
   		
   	}
	}
	echo '<div class="row" align="center">
	<p align="center">La ricerca ha generato il seguente risultato:</p>';
		 //echo CHtml::label('Risultati',$lab); 
		 echo '<br></br>';
		 echo CHtml::listBox('prova2','ANAGRA_ID',CHtml::listData($docente,'ID','VALORE'));
		 //echo CHtml::error($model,'NOME'); 
	echo '</div><br></br><br></br><br></br>';
	
	
	
	
	echo CHtml::submitButton('Scegli',array('submit'=>'/tirocini/index.php?r=anagrafe/view')); 	
	echo CHtml::endForm(); 	
}
else{
	
$this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		'NOME',
		'ANAGRA_ID',
		'E_MAIL',
		'INDIRIZZO',
		'NOTE',
		'TELEFONO_3',
		'CODICE_FISCALE',
		'TELEFONO_1',
		'SESSO',
		'COGNOME',
		'DATA_NASCITA',
		'TELEFONO_2',
		'COMUNE_COMUNE_ID',
		'COMUNE_COMUNE_ID_NASCE',
		'CAP',
		'DOMICILIO',
		'CAP_DOM',
		'COMUNE_COMUNE_ID_DOMICILIA',
		'ACCESSO_PORTAL',
		'STATO_CIVILE',
		'FAX',
		'CELLULARE',
		'CITTADINANZA',
	),
));} ?>
	
	echo CHtml::endForm(); 	
}
else{
	
$this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		'NOME',
		'ANAGRA_ID',
		'E_MAIL',
		'INDIRIZZO',
		'NOTE',
		'TELEFONO_3',
		'CODICE_FISCALE',
		'TELEFONO_1',
		'SESSO',
		'COGNOME',
		'DATA_NASCITA',
		'TELEFONO_2',
		'COMUNE_COMUNE_ID',
		'COMUNE_COMUNE_ID_NASCE',
		'CAP',
		'DOMICILIO',
		'CAP_DOM',
		'COMUNE_COMUNE_ID_DOMICILIA',
		'ACCESSO_PORTAL',
		'STATO_CIVILE',
		'FAX',
		'CELLULARE',
		'CITTADINANZA',
	),
));} ?>



I have a problem when i redirect to a view page....
In the button:
echo CHtml::submitButton('Scegli',array('submit'=>'/tirocini/index.php?r=anagrafe/view')); 

how do I retrieve the value 'anagra_id' from the dropdownlist and insert the address of the button??
Help meeeeeee...
-1

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 07 June 2010 - 07:02 AM

This code is something of never seen before.

I cannot even immagine if is a controller or a view.. I suppose a view because I don't see any class CController, but it has no the style of a view.

My advice is to choose if you want to use Yii or not. If you want to use the framework, you have to think about the style, to do controller works (like reading $post, quering the database) in the controller, and doing view works (displaing the data prepared from controller) in a view.

If you don't need a framework simply don't use. Your code looks like code of a "pure coder". For achive result and use effectivly the framework you sould know very good the structure and the MVC concept.

Yii is a "strongly MVC" framework, if you try do do something not MVC everithing begin to be very complex.

The better way for achive a result is to restart implement your page by using a crud, a page authomatically generated by Yii.

And then edit this page step by step, never going against the framework philosophy.

In general you should never need Yii::app()->db->connection but you should use activeRecords, you should not do a loop of queries but using a conditoin for retrive the results you need.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users