Ayuda User input advanced

Hola estoy guiandome del ejemplo de Yii Playground pero no logro la funcionalidad.




<script type="text/javascript">


	function updateEditForm(target_id) {

		var id =$.fn.yiiGridView.getSelection(target_id);		

        alert('clave:'+id);


   		$.getJSON('<?php echo $this->createUrl('userinputData'); ?>&id='+id,

			function(data) {

				$('#PRV_FechaIngreso').val(data.PRV_FechaIngreso);


			});

	}


</script>



y en el controlador;




    public function actionUserinputData() {


	$item_id =(int)$_GET['id'];


	$model =proveedor::model()->findByPk($item_id);

    

	$res =array(

		'PRV_FechaIngreso'=>$model->PRV_FechaIngreso,


	);


	echo CJSON::encode($res);

    }



Espero ayudas :(




<?php echo $this->createUrl('userinputData'); ?>&id='+id,

Looks wrong, if you use ‘path’ url format, the url would be

controller/action/param/value/&id=1

wrong

the url is $.getJSON(’/proyecto/index.php?r=proveedor/userinputData&id=’+id,

but in the example is like that, how i can send the id? if i remove &id=’+id ? …

Hola Luisis, cual es la funcionalidad? qué es lo que esperas? qué es lo que no funciona?

Hola Antonio, que al seleccionar una fila de una datagrid:




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'proveedor-grid',

	'dataProvider'=>$model->search(),

        'selectionChanged'=>'updateEditForm',

	'filter'=>$model,

 ...



Me cargue los datos dentro de un formulario, yo tengo en mi vista el formulario y debajo la grilla.

Estava guiandome del ejemplo : My link

Pero cuando quiero acceder al controlador mediante el javascript y $.getJSON … parece q no accediera

Acabo de verlo, podrías mostrar el código que usas para el CGridView? Quizás el problema es que no lo has configurado debidamente. Has iniciado la propiedad ‘selectionChanged’=>‘updateEditForm’,?

Has visto si la petición es correcta y la devolucion en JSON también? Pon el vinculo directo a ver si está bien…

Puedes mostrar el javascript resultante?

Un saludo

Estees el javascript




<script type="text/javascript">


	function updateEditForm(target_id) {

		var id =$.fn.yiiGridView.getSelection(target_id);		

        alert('clave:'+id);


   		$.getJSON('/proyecto/index.php?r=proveedor/userinputData&id='+id,

			function(data) {

				$('#PRV_FechaIngreso').val(data.PRV_FechaIngreso);


			});

	}




</script>




¿Has mirado con el FireBug en el Firefox las llamadas con AJAX y el resultado?

Eso te puede guiar.

Saludos.

userinputData es tu accion? y que resultados te da si la pones directamente en tu barra de direcciones? http://localhost/proyecto/index.php?r=proveedor/userinputData&id=

Ya no digo nada de Firebug… prueba tu peticion directamente en la barra y dinos los resultados

Hola gracias x sus rptas, ya me di cuenta de mi error u horror :mellow: , olvidé agregar la acción en los permisos:





    public function accessRules()

	{return array(

		array('allow',

                      'actions'=>array('index','update','delete','userinputData'),

				   'users'=>array('jefe'),

			     ),

		);

	}



al final este javascript quedó en mi vista:




<script type="text/javascript">


	function updateEditForm(target_id) {

		var id =$.fn.yiiGridView.getSelection(target_id);		

      

   		$.getJSON('<?php echo $this->createUrl('userinputData'); ?>&id='+id,

			function(data) {

             $('#proveedor_PRV_RUC').val(data.PRV_RUC);

             $('#proveedor_PRV_RazSocial').val(data.PRV_RazSocial);

             $('#proveedor_PRV_Direccion').val(data.PRV_Direccion);

             $('#proveedor_PRV_Telefono').val(data.PRV_Telefono);

             $('#proveedor_PRV_Fax').val(data.PRV_Fax);

             $('#proveedor_PRV_PagWeb').val(data.PRV_PagWeb);

             $('#PRV_FechaIngreso').val(data.PRV_FechaIngreso);

             if(data.PRV_Activo=='1')

             $('#proveedor_PRV_Activo').empty().attr('checked','true');


			});  

            

	}


</script>



Mi controlador:




    public function actionUserinputData() {

    

	$item_id =(int)$_GET['id'];

	$model =proveedor::model()->findByPk($item_id);


	$res =array(

    'PRV_RUC'=>$model->PRV_RUC,

    'PRV_RazSocial'=>$model->PRV_RazSocial,

    'PRV_Direccion'=>$model->PRV_Direccion,

    'PRV_Telefono'=>$model->PRV_Telefono,

    'PRV_Fax'=>$model->PRV_Fax,

    'PRV_PagWeb'=>$model->PRV_PagWeb,

    'PRV_FechaIngreso'=>$model->PRV_FechaIngreso,

    'PRV_Activo'=>$model->PRV_Activo,


	);


	echo CJSON::encode($res);

    }



Espero sirva a alguien q pase x lo mismo :rolleyes: