Yii Framework Forum: Form Ricerca - Yii Framework Forum

Jump to content

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

Form Ricerca Rate Topic: -----

#1 User is offline   pippuccio76 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 10-September 13

Posted 01 February 2014 - 03:45 PM

Allora con filezilla avevo creato un casino e le varie pagine che cambiavo non erano quelle giuste :(. Mi domando però come passo i dati da una pagina all'altra ripropongo il tutto questa volta funzionante :


#model

<?php


class SearchForm extends CFormModel
{
	public $nome;
	

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('nome', 'required'),
			// email has to be a valid email address
			array('nome', 'length', 'min'=>3, 'max'=>100),
		);
	}


}


controller *con problemi:
ecco i metodi che mi interessano
 public function actionSearch()
	{
		
              /**
	 * Displays the contact page
	 */
	
		$model=new SearchForm;
                if($model->validate()){
                     if(isset($_GET['SearchForm'])){
                        $dati=$model->attributes=$_GET['SearchForm'];
                        
                     }
                        
                }
		
		$this->render('search',array('model'=>$model));
	
	}
        
        public function actionRisultati()
	{
		
              /**
	 * Displays the contact page
	 */ 
                $nome=$SearchForm[nome];
                 // query 
                $sql = "SELECT nome FROM nomi where nome like %$nome% ";

                // esecuzione della query
                $command=$connection->createCommand($sql);

                //prendo i risultati
                $data[row]=$command->queryAll();


                //conto i risultati 
                $data[numRighe]=$command->execute();   // execute the non-query SQL

                $data[dataReader]=$command->query();
                
		
		$this->render('risultati,$data');

		
	
	}


view


<?php
/* @var $this fIL,Controller */
/* @var $model  SearchForm */
/* @var $form CActiveForm */

$this->pageTitle=Yii::app()->name . ' Ricerca Nomi';
$this->breadcrumbs=array(
	'Ricerca Nomi',
);
?>

<h1>Ricerca</h1>

<?php if(Yii::app()->user->hasFlash('search')): ?>

<div class="flash-success">
	<?php echo Yii::app()->user->getFlash('search'); ?>
</div>

<?php else: ?>



<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl('nomi/risultati'),
	'method'=>'GET',
	
)); ?>

	<?php echo $form->errorSummary($model); ?>

		<div class="row">
		<?php echo $form->labelEx($model,'nome'); ?>
		<?php echo $form->textField($model,'nome',array('size'=>60,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'nome'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Ricerca'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php endif; ?>


Inoltre appena accedo alla pagina search mi dice che c'è un errore del campo bianco , vorrei che al submit mi dia l'errore...
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