Sergio_HW
Sergio_HW

Reputation: 155

Yii Ajax error 500

I did a master detail with a Clistview that generate a Cgridview but when i click in the link what call the function crash and say:

Error 500: <h1>PHP Error [8]</h1>
<p>Undefined offset: 0 (C:\APP\htdocs\yii\yiitest\protected\controllers\ZfInmueblesController.php:176)</p>

I thought it was ajax but I have a filter form without ajax and pagination also said same error.

CONTROLLER:

$dataProviderDoc = new CActiveDataProvider(ZfDocumentacionInmueble::model(), array(
            'keyAttribute'=>'doc_id',
            'criteria'=>array(
                'condition'=>'zf_inmuebles_inmueble_id=-1',
            ),
        ));

        if(Yii::app()->request->isAjaxRequest){
            // el update del CGridView Productos hecho en Ajax produce un ajaxRequest sobre el mismo
            // action que lo invoco por primera vez y el argumento fue pasado mediante {data: xxx} al // momento de hacer el update al CGridView con id 'productos'
            $zf_inmuebles_inmueble_id = $_GET[0];
            // actualizas el criteria del data provider para ajustarlo a lo que se pide:
            $dataProviderDoc->criteria = array('condition'=>'zf_inmuebles_inmueble_id='.$zf_inmuebles_inmueble_id);
            // para responderle al request ajax debes hacer un ECHO con el JSON del dataprovider
            echo CJSON::encode($dataProviderDoc);
        }

VIEW (index):

function mostrarDetalles($id){
        // no olvides configurar tu CActiveDataProvider con: 'keyAttribute'=>'idcategoria',
        alert($id);
        //var doc_id = $.fn.yiiListView.getSelection('inmuebles');
        var id_inm = $id;
        $.fn.yiiGridView.update('docs',{ data: id_inm });
    }

VIEW (_view):

echo CHtml::link('DOCUMENTACIÓN '.$img, '#documentacion', array('data-toggle' => 'modal','onclick'=>"{mostrarDetalles($id)}",));

ERROR GET:

PHP Error [8]

Undefined offset: 0 (C:\APP\htdocs\yii\yiitest\protected\controllers\ZfInmueblesController.php:177)

#0 C:\APP\htdocs\yii\yiitest\protected\controllers\ZfInmueblesController.php(177): CWebApplication->handleError()#1 C:\APP\htdocs\yii\framework\web\actions\CInlineAction.php(49): ZfInmueblesController->actionIndex()#2 C:\APP\htdocs\yii\framework\web\CController.php(308): CInlineAction->runWithParams()#3 C:\APP\htdocs\yii\framework\web\filters\CFilterChain.php(133): ZfInmueblesController->runAction()#4 C:\APP\htdocs\yii\yiitest\protected\modules\cruge\components\CrugeAccessControlFilter.php(90): CFilterChain->run()#5 C:\APP\htdocs\yii\framework\web\filters\CFilter.php(38): CrugeAccessControlFilter->preFilter()#6 C:\APP\htdocs\yii\framework\web\filters\CFilterChain.php(130): CrugeAccessControlFilter->filter()#7 C:\APP\htdocs\yii\framework\web\filters\CFilter.php(40): CFilterChain->run()#8 C:\APP\htdocs\yii\framework\web\CController.php(1145): CAccessControlFilter->filter()#9 C:\APP\htdocs\yii\framework\web\filters\CInlineFilter.php(58): ZfInmueblesController->filterAccessControl()#10 C:\APP\htdocs\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter()#11 C:\APP\htdocs\yii\framework\web\CController.php(291): CFilterChain->run()#12 C:\APP\htdocs\yii\framework\web\CController.php(265): ZfInmueblesController->runActionWithFilters()#13 C:\APP\htdocs\yii\framework\web\CWebApplication.php(282): ZfInmueblesController->run()#14 C:\APP\htdocs\yii\framework\web\CWebApplication.php(141): CWebApplication->runController()#15 C:\APP\htdocs\yii\framework\base\CApplication.php(180): CWebApplication->processRequest()#16 C:\APP\htdocs\yii\yiitest\index.php(13): CWebApplication->run()

Upvotes: 0

Views: 1763

Answers (2)

Rafay Zia Mir
Rafay Zia Mir

Reputation: 2116

You are using $GET[0]. In your given code index 0 is not defined thats y it gives error. Array always consists of key=>value pair.

array(
    key  => value,
    key2 => value2,
    key3 => value3,
    ...
)


In your code $.fn.yiiGridView.update. Actually this code automatically send ajax request to controller.
As you are sending data as {data: id_inm } So you need to access this as $_GET['id_inm'].

$zf_inmuebles_inmueble_id = $_GET['id_inm'];

Add

CVarDumper::Dump($_GET,100,true);
die();

before line 177 at which you are getting error

Upvotes: 0

Burhan &#199;etin
Burhan &#199;etin

Reputation: 676

if there is a variable in your function, set it like,

public function actionName($_GET[0] = 0){
    echo $_GET[0];
}

Upvotes: 1

Related Questions