PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label cgridview. Show all posts
Showing posts with label cgridview. Show all posts

Tuesday, March 8, 2022

[FIXED] Yii: Can not Display Data in Grid View

 March 08, 2022     cgridview, php, yii, yii-extensions     No comments   

Issue

I can't list data in grid using yii framework. My controller is Sitecontroller.php, My view is list_jobseeker.php.

I got the error:

Parse error: syntax error, unexpected '*', expecting ']' in C:\wamp\www\yii_new\framework\base\CComponent.php(612) : eval()'d code on line 1

Anybody give any suggestion to correct these issue?

My controller:

 public function actionlist_jobseeker()
  {
  $session_id=Yii::app()->session['user_id']; 
  if ($session_id == "")
    {
        $this->redirect( array('/employee/site/login'));
    }
  $user_id  =$session_id;
  $items = Yii::app()->db->createCommand()
     ->select('*')
     ->from('job_seeker_profile s')
     ->join('job_profile j','s.user_id = j.user_id')
     ->order('s.id')
     ->queryAll();
     $this->render('list_jobseeker',array('items' =>$items));
}

My view page - list_jobseeker.php

<h1>View Jobseeker</h1>

<div class="flash-success">

</div>

<div class="form">
<?php
 $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'rates-phase-grid',
   'htmlOptions' => array('class' => 'table table-striped table-bordered table-hover'),
    'dataProvider'=>new CArrayDataProvider($items),
    'columns' => array(
        array(
            'name' => 'Name',
            'type' => 'raw',
            'value' => 'CHtml::encode($data[*]->name)',
            'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz'),

     ),
        array(
            'name' => 'Email',
            'type' => 'raw',
            'value' => 'CHtml::encode($data[*]->email)',
            'htmlOptions' => array('style'=>'width:250px;','class'=>'zzz')

        ),
        array(
            'name' => 'Password',
            'type' => 'raw',
            'value' => 'CHtml::encode($data[*]->password)',
            'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz')
        ),
        array(
            'name' => 'Contact No',
            'type' => 'raw',
            'value' => 'CHtml::encode($data[*]->contact_no)',
            'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')

        ),
         array(
            'name' => 'Gender',
            'type' => 'raw',
            'value' => 'CHtml::encode($data[*]->gender)',
            'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')

        ),


        array(
            'class' =>'CButtonColumn',
            'deleteConfirmation'=>'Are you sure you want to delte this item?',
            'template'=>'{update}{delete}',

            'buttons' =>array('update'=>array(

             'label'=>'edit',
     'url'=>'Yii::app()->controller->createUrl("UpdateJob",array("id"=>$data["id"]))',

                ),
             'delete'=>array('label'=>'delete',
     'url'=>'Yii::app()->controller->createUrl("DeleteJob",array("id"=>$data["id"]))'),

                )
            )
          ),
));
?>

</tbody>


Solution

change all the [*]

 $data[*]->name

to match columns

$data["name"]


Answered By - Developerium
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Yii filter search working for one relation but not for other

 March 08, 2022     activerecord, cgridview, yii     No comments   

Issue

I am using Yii GridView filter and my data comes from Purcahses table. That tables realted to 1 .vendors 2 .clients Below are my relations in Purchases Model

 'vendor' => array(self::BELONGS_TO, 'Vendors', 'Vendor'),
 'client' => array(self::BELONGS_TO, 'Clientsinfo', 'clientID'),

and i am using that relations in my admin view , Below is code of admin.php file

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'purchases-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
    array(
        'name' => 'Vendor',
        'value' =>'$data->vendor->VendorName',
    ),
    array(
        'name' => 'clientID',
         'value' =>'$data->client->Company'
    ),

    array(
        'name' => 'PurchaseType',
        'value' => 'Purchasetype::model()->findByPk($data->PurchaseType)->PurchaseType',
        'filter' => '',
    ),

),
));

and lastly here is model search function where is use with and together to get data from other tables

public function search() {
    $criteria = new CDbCriteria;
    $criteria->together = true;
    $criteria->with = array('vendor');
    $criteria->with = array('client');
    $criteria->compare('PurchaseType', $this->PurchaseType);
    $criteria->compare('vendor.VendorName', $this->Vendor, true);
    $criteria->compare('client.Company', $this->clientID, true);
   return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}

Getting data from client successufully , but when i use vendor fitter it throw me error below

CDbException

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'vendor.VendorName' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT t.PurchaseID ) FROM purchases t LEFT OUTER JOIN clientsinfo client ON (t.clientID=client.ClInfoID ) WHERE ((Vendor=:ycp0) AND (vendor.VendorName LIKE :ycp1)) (C:\xampp\htdocs\laurenparker\framework \db\CDbCommand.php:543)

#0 C:\xampp\htdocs\laurenparker\framework\db\CDbCommand.php(433): CDbCommand-

queryInternal('fetchColumn', 0, Array)


Solution

Youre overriding relations in criteria. Change this:

$criteria->with = array('vendor');
$criteria->with = array('client');

To this:

$criteria->with = array('vendor', 'client');


Answered By - Yupik
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, February 28, 2022

[FIXED] How to write this html part in CGridView Yii1.1

 February 28, 2022     cgridview, php, yii, yii1.x     No comments   

Issue

This is the column(It is a numerical input with range of numbers between 1 and 60), that I want to add into CGridView, but I want to append terminalcode to the id of this input. In this code everything is working properly, but terminalcode is not appending with id.

   array(
            'header' => 'Validity',
            'name' => 'validity',
            'value' => function(){ return '<input type="number" id="tentacles".$data["terminalcode"] name="tentacles" min="1" max="60">';},
            'type' => 'raw'
    )


Solution

You need to adjust your return value and add $data parameter in value function. Your code would become like this

array(
    'header' => 'Validity',
    'name' => 'validity',
    'value' => function($data){ return '<input type="number" id="tentacles'.$data["terminalcode"].'" name="tentacles" min="1" max="60">';},
    'type' => 'raw'
),

I hope your problem will be solved.



Answered By - MAZ
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, February 15, 2022

[FIXED] CArrayDataProvider with CGridView pagination Yii

 February 15, 2022     cgridview, php, yii     No comments   

Issue

I'm trying to do a pagination on a CGridView using CArrayDataProvider (my $rawData is a custom array - not from a DB/model). So, In the controller`s action a have the following:

$form = new SearchUser;//here I have SearchUser form that extends CFormModel with the following attributes: 'id', 'name', 'surname', 'phone', 'address'
$users = array();
if (isset($_POST['SearchUser'])) {
....//prepare users array from my custom source-> not from DB/models etc
}

$dataProvider=new CArrayDataProvider($users, array(
            'id'=>'id',
            'keys'=>array('name', 'surname', 'phone', 'address'),
            'sort'=>array(
                'attributes'=>array(
                    'name', 'surname', 'phone', 'address'
                ),
            ),
            'pagination'=>array(
                'pageSize'=>15,
            ),
        ));

And:

$this->render('index', array('dataProvider'=>$dataProvider, 'form'=>$form));

On index.php I have:

...
<?php echo CHtml::link('Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$form,
)); ?>
</div><!-- search-form -->
<?php

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(

    array(
        'name' => 'Name',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["name"])'
    ),
    array(
        'name' => 'Surname',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["surname"])'
    ),/*
    array(
        'name' => 'Phone',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["phone"])'
    ),*/
    array(
        'name' => 'Address',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["address"])'
    ),
),
'enablePagination'=> true,
));

The first page is displayed correctly but when I select another page, my filter is lost and all data are displayed in the grid instead of "filtered" ones.


Solution

Not sure it will solve your problem, but in your CArrayDataProvider you use id to define the name of the key field instead of keyField. You could try the following:

$dataProvider=new CArrayDataProvider($users, array(
    'id'=>'users',
    'keyField' => 'id', 
    'keys'=>array('id','name', 'surname', 'phone', 'address'),
    'sort'=>array(
        'attributes'=>array(
            'name', 'surname', 'phone', 'address'
        ),
    ),
    'pagination'=>array(
        'pageSize'=>15,
    ),
));


Answered By - darkheir
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, January 12, 2022

[FIXED] CJuiDialog will not re-open with CGridview inside

 January 12, 2022     cgridview, cjuidialog, jquery, php, yii     No comments   

Issue

I've got a number of links containing parameters which will open a dialog which is populated with an ajax call.

sample link:

<a href="javascript:void(0)" id="attach_file_project_454" class="attach_timesheet_file" data-id="454" data-week-start="2017-08-18" data-week-end="2017-08-24">Attach File</a>

Here's the trigger for the modal:

$(".attach_timesheet_file").on("click", function(e) {
    e.preventDefault();
    var url = "<?=Yii::app()->createUrl('admin/timesheetNew/attachTimesheet')?>";
    var id = $(this).data("id");
    var weekStart = $(this).data("week-start");
    var weekEnd = $(this).data("week-end");
    $.ajax({
        type: 'POST',
        url:url,
        data: {
            id: id,
            week_start: weekStart,
            week_end: weekEnd
        },
        success: function(data) {
            var modal = $("#attachFileModal");
            try{
                modal.html(data);
            }
            catch(error)
            {
                console.log(error);
            }
            modal.dialog('open');
            return true;
        }
    })
});

The basic action called by the ajax:

public function actionAttachTimesheet(){
    $projectId = Yii::app()->request->getPost('id', null);
    $reportedWeekStart = Yii::app()->request->getPost('week_start', null);
    $reportedWeekEnd = Yii::app()->request->getPost('week_end', null);

    $this->renderPartial("_attachTimesheet", [
        'projectId' => $projectId,
        'reportedWeekStart' => $reportedWeekStart,
        'reportedWeekEnd' => $reportedWeekEnd,
        'dataProvider' => TimesheetAdditionalFile::additionalFilesDataProvider($projectId, $reportedWeekStart, $reportedWeekEnd)
    ], false, true);
}

And finally the CGridView widget inside the dialog:

$this->widget('zii.widgets.grid.CGridView', [
    'id' => 'files-grid',
    'dataProvider' => $dataProvider,
    'columns' => [
        [
            'name' => 'filename',
            'header' => 'File Name',
            'value' => 'CHtml::link($data["filename"], Yii::app()->baseUrl . TimesheetNew::FILES_FOLDER . $data["filename"], ["class" => ($data["filetype"] == "pdf")?"fancybox_pdf":"fancybox_picture"])',
            'type'=>'raw',
            'headerHtmlOptions'=>array('style'=>'width: 250px'),
        ],
        [
            'class' => 'CButtonColumn',
            'template' => '{delete}',
            'buttons' => [
                'delete' => [
                    'label' => 'Delete',
                    'imageUrl' => null,
                    'url' => 'Yii::app()->createUrl("admin/timesheetNew/deleteFile", ["id" => $data["id"]])'
                ]
            ],
            'deleteConfirmation'=>'Are you sure you want to delete this file?',
        ]
    ]
]);

I've also used qq.FileUploader as well as fancybox inside the modal, but these do not seem to interfere with anything.

When I try to click any such "attach file" link, the dialog opens just fine and everything works as intended. I'm seeing my gridview, and I can add and delete files. However, when I close the dialog, it won't open this link or any other "attach file" links.

The error I'm getting in the console is this after re-clicking a link:

Uncaught TypeError: modal.dialog is not a function

I'm only experiencing this when using the gridview, when I comment out this widget code, I can freely open and close these dialogs at will.

Any help would be greatly appreciated :)


Solution

The solution was rather easy. By adding these lines at the top of the view file, dialogs can once again be opened and closed indefinitely.

Yii::app()->getClientScript()
    ->scriptMap = array(
    'jquery.js' => false,
    'jquery-ui.min.js' => false
);


Answered By - kurt
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, January 9, 2022

[FIXED] Decimal Format in Yii TBGridview

 January 09, 2022     cgridview, php, yii     No comments   

Issue

I have code like this :

<?php 
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'appliances-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
        array(
            'name'=>'price',
            'type'=>'number',
            'htmlOptions'=>array('style' => 'text-align: right;'),
        ),
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'template'=>'{update}{delete}'
        ),
    ),
)); 
?>

the result is integer number only and search filter is work, how to change it into decimal format but search filter still working ?
I tried to change it into :

array(
    'name'=>'price',
    'type'=>'number',
    'htmlOptions'=>array('style' => 'text-align: right;'),
    'value'=>function($data)
             {
                return number_format($data->price,2,',','.');
             },
),

But it makes search filter not working properly.


Solution

I found the answers here :

  1. Yii Number Formatting
  2. How to format numeric string using C.Gridview - Yii

And also I found this link Yii , show different date format in cgridview



Answered By - Cuheguevara
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] CGridView show columns

 January 09, 2022     cgridview, yii     No comments   

Issue

I have a status field, which should be highlighted in green or red, depending on where 0 or 1. I have the following code, but it does not work, all the cells in a single color paint. Tell me how to do such a thing?

array(
            'name' => 'status',
            'htmlOptions' => array('class' => $model->status == 0 ? "non_payed_status" : "payed_status"),
            'filter' => false,
        ),

Solution

You have to override CDataColumn class, look at this, maybe will help:

http://www.yiiframework.com/wiki/314/cgridview-use-special-variable-data-in-the-htmloptions-of-a-column-i-e-evaluate-htmloptions-attribute/



Answered By - user2883814
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to sort and filter with checkbox in yii

 January 09, 2022     cgridview, php, yii     No comments   

Issue

I have gridview with filters+checkboxes like below: filters+checkboxes

Gridview is filtered when checkbox is checked and its working v. nice but when i'm clicking on the column name to sort columns sort is taking controll over the filters and they just stop working...

I cant even unclick checkboxes and change values in filters inputs cause "sort" keeps values from before i clicked column name.

Is there any way to repair this?

My search function in model looks like below:

public function Search(): CActiveDataProvider
{
    $request = Yii::app()->request;
    $requestusr = $request->getParam('Users');

    $this->xyz_name_filter = isset($requestusr['xyz_name_filter']) ? $requestusr['xyz_name_filter'] : 1;
    $this->xyz_surname_filter = isset($requestusr['xyz_surname_filter']) ? $requestusr['xyz_surname_filter'] : 1;
    $this->xyz_street_filter = isset($requestusr['xyz_street_filter']) ? $requestusr['xyz_street_filter'] : 0;

    $criteria = new CDbCriteria();
    $this->xyz_name_filter == 1 ? $criteria->compare('t.xyz_name', $this->xyz_name, true) : null;
    $this->xyz_surname_filter == 1 ? $criteria->compare('t.xyz_surname', $this->xyz_surname, true) : null;
    $this->xyz_street_filter == 1 ? $criteria->compare('t.xyz_street', $this->xyz_street, true) : null;

    return new CActiveDataProvider(
        $this, array(
            'criteria' => $criteria,
            'pagination' => array(
                'pageSize' => $this->pagesize,
            ),
        )
    );
}

Thanks for reply.


Solution

The problem wos in config... adding line:

'admin/<lang:[a-z]{2}>/<controller:\w+>/<action:\w+>'=>'admin/<lang>/<controller>/<action>'

solves the problem.



Answered By - TomLi
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing