0

I have some datas stored in my table Jobs. How can I display them in a tabular form in my view section? I have visited the Yii forums but have not got any specific options to perform the action.

The action for view job:

public function actionViewJob() {
    $criteria = "";
    $model = new ViewJob();

    /* What Should I do Here */

    $this->render('viewjob', array(
        'model' => $model
    ));
}

And the corresponding view to list data from database:

/* What should I do Here.  */
<h1>View Jobs</h1>

<div class="flash-success"></div>
<div class="form">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="filtertable" style="float: left;">
        <thead>
            <tr>
                <th width="11%" class="rowtop">No</th>
                <th width="24%" class="rowtop">Title</th>
                <th width="10%" class="rowtop">Description</th>
                <th width="10%" class="rowtop">No_Vacancy</th>
                <th width="10%" class="rowtop">Contact Email</th>
                <th width="10%" class="rowtop">Edit</th>
                <th width="10%" class="rowtop">Delete</th>
            </tr>
        </thead>
        <tbody>
            <?php // foreach ($posts as $post): ?>
            <tr>
                <td width="11%">
                    <?php ?>
                </td>
                <td width="24%">
                    <?php ?>
                </td>
                <td width="14%">
                    <?php ?>
                </td>
                <td width="14%">
                    <?php ?>
                </td>
                <td width="14%">
                    <?php ?>
                </td>
                </a>
                </td>
                </a>
                </td>
            </tr>
            <?php //endforeach; ?>
        </tbody>
    </table>
    <!-- form -->

2 Answers 2

1

In your action, call your view.

public function actionViewJob() {
        $model = new Job('search');

        $params =array('model'=>$model,
        );

        $this->render('viewjob', $params);
    }

Get your data as a CActiveDataProvider object.

In your model, create a search function

public function search() {
    $criteria=new CDbCriteria;

    // TODO: Add other search criteria here
    $criteria->compare('username','Tom',true);

    return new CActiveDataProvider('Jobs', array(
        'criteria'=>$criteria,
        'sort'=>array(
            'defaultOrder'=>'username ASC',
        ),
    ));
}

Then, in your view

$this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $model->search(),
        'filter' => $model,
        'columns' => array(
            array(
                'name' => 'title',
                'type' => 'raw',
                'value' => 'CHtml::encode($data->title)'
            ),
            array(
                'name' => 'description',
                'type' => 'raw',
                'value' => 'description',
            ),
        ),
    ));
Sign up to request clarification or add additional context in comments.

Comments

0

At first you should get table data in controller via CActiveDataProvider. And then in view you can use widget - CGridView. Using this widget you can set params that you need. Columns, filters etc. Also you can paste your code, and we will try to decide your problem. Yii is very easy :)

3 Comments

Thanks,but your's solution is in core php,I want to knowno how to do it in yii.?
Sagi, @mitul marsonia's answer in not in 'core php', but is Yii specific. Using CGridView is indeed the Yii way of printing your data as a table.
crafter,my comment was on his previous answer,he later edited his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.