Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:12+00:00 2026-06-13T02:07:12+00:00

I have a CGridView with a CCheckBoxColumn and selectableRows = 2. Users can select

  • 0

I have a CGridView with a CCheckBoxColumn and selectableRows = 2. Users can select multiple rows of my grid view.

The gridview is for a list of unapproved comments and I want to be able to select comments to approve, hit an “Approve” button and update a field in the comments table for each comment that was approved.

How can I do this?

I’m open to an ajax solution but really what I want to know is how to get the list of comment ids inside my controller action code with a normal post. I’d prefer a solution that doesn’t involve javascript unless that is the only option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:07:14+00:00Added an answer on June 13, 2026 at 2:07 am

    I was able to get this working without depending on javascript. The steps are as follows:

    Add a form to your view file

    This will allow the checkbox values, which are html input elements, to be posted to your controller.

    <?php echo CHtml::beginForm(); ?>
    
    <?php $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider'=>$dataProvider,
        'selectableRows' => 2,
        'columns' => array(
            array(
                'id' => 'selectedIds',
                'class' => 'CCheckBoxColumn'
            ),
            'id',
            'username',
            'content',
            array(
                'name' => 'created',
                'value' => '$data->created'
            ),
        ), 
    ));
    ?>
    
    <div>
    <?php echo CHtml::submitButton('Approve', array('name' => 'ApproveButton')); ?>
    <?php echo CHtml::submitButton('Delete', 
    array('name' => 'DeleteButton',
    'confirm' => 'Are you sure you want to permanently delete these comments?'));
    ?>
    </div>
    
    <?php echo CHtml::endForm(); ?>
    

    Note by passing in a “Name” option to the submitButton it allows to know which button was clicked in the controller.

    Give your check box column an id

    Previously I had:

    'columns' => array(
        array(
            'class' => 'CCheckBoxColumn'
        ),
    

    I changed this to:

    'columns' => array(
        array(
            'id' => 'selectedIds',
            'class' => 'CCheckBoxColumn'
        ),
    

    Now you can reference your selected rows as an array via $_POST['selectedIds']. By default the CCheckBoxColumn will use the primary key of your model items in the gridview (but you can change this), so selectedIds will be an array of the selected primary keys.

    Modify controller to process the selected rows

    public function actionApprove()
    {
        if (isset($_POST['ApproveButton']))
        {
            if (isset($_POST['selectedIds']))
            {
                foreach ($_POST['selectedIds'] as $id)
                {
                    $comment = $this->loadModel($id);
                    $comment->is_published = 1;
                    $comment->update(array('is_published'));
                }
            }
        }
    
        // similar code for delete button goes here
    
        $criteria = new CDbCriteria();
        $criteria->condition = 'is_published = 0';
        $criteria->order = 'created DESC';
    
        $dataProvider = new CActiveDataProvider('Comment');
        $dataProvider->criteria = $criteria;
    
        $this->render('approve', array(
            'dataProvider' => $dataProvider,
        ));
    }
    

    I used this Yii wiki article to help me come up with this solution: Working with CGridView in Admin Panel

    Not sure if this is the ideal way to do it but it works. I’m open to suggestions for improvement or other methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have GridView which I can select a row. I then have a button
Have a gridview control which will show X amount of rows. I want to
I have GridView and this grid has setup paging, but this paging not show
I have GridView that allows select. It takes data from EntityDataSource . How do
I have gridview which contains 60 rows and each row has 4 radiobutton option
I have a CGridView widget for Lesson model $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'lesson-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, ...
I have set up a CGridView widget in my application. It displays a list
I have a grid view that lists contents of a table, table has column
I have GridView on my page: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE
I have a gridview and I have a button on it.I want, if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.