best practiese practice who to handle szenarios

Hi,

I have an model to store informations to an NoSQL DB. Because of the flexible DB Layout it’s possible to store different kind of information at the DB (at one “table”).

So one record could contain the User IP and a Link to an webpage. (case A)

The next record could contain the user IP and an document, which is uploaded by the user, like an image. (case B )

The question is: how to handle this on application side?

Right now, i use scenarios to validate the input.

On controller side, i create a model for every possible case, like this:


		$modelURL= new myModel('createURL');

		$modelUpload= new myModel('createUpload');

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

				'modelURL'=>$modelURL,

				'modelUpload'=>$modelUpload

		));



On view side, i use an CActiveFrom Widget which contains an input field for every case (Textfield for case A and FileUpload for case B ) and an submit button for every case. It will be look like that (not tested)


<?php $form = $this->beginWidget('CActiveForm', array(

				   'enableClientValidation'=>true,

				    'action' =>CController::createUrl('Qr/create'),

   [...]

 ?>




<div >  <--- Input for case A

    <?php echo $form->textField($modelURL,'Z');

          echo $form->error($modelURL,'Z');

          echo CHTML::ajaxSubmitButton('save URL',

          				CController::createUrl('Qr/create',array('szenario=>"URL")),

 									   array('success'=> '...'

          							   		)

          						);

    ?>

</div>


<div >  <--- Input for case B

    <?php echo echo $form->fileField($modelUpload, 'image');

          echo $form->error($modelUpload,'Z');

          echo CHTML::ajaxSubmitButton('Upload',

          				CController::createUrl('Qr/create',array('szenario=>"Upload")),

 									   array('success'=> '...'

          							   		)

          						);

    ?>

</div>




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

What do you think? Is this the right way?

One problem is Ajax Validation, because the CActiveForm Widget only supports one action (for validation).

Or is it best practice to create on CActiveForm for every case (for every scenario)

…or should i use an own view for every case an do an $formULS=renderPartial on controller side in oder to pass the form content to an man view?

Thank you for sharing your ideas. :slight_smile:

Rall0r