Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Yii中以表格形式显示数据库中的数据_Php_Templates_Yii - Fatal编程技术网

Php 在Yii中以表格形式显示数据库中的数据

Php 在Yii中以表格形式显示数据库中的数据,php,templates,yii,Php,Templates,Yii,我的表作业中存储了一些数据。如何在视图部分以表格形式显示它们?我访问了Yii论坛,但没有任何具体的选项来执行该操作 查看作业的操作: public function actionViewJob() { $criteria = ""; $model = new ViewJob(); /* What Should I do Here */ $this->render('viewjob', array( 'model' => $model

我的表作业中存储了一些数据。如何在视图部分以表格形式显示它们?我访问了Yii论坛,但没有任何具体的选项来执行该操作

查看作业的操作:

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

    /* What Should I do Here */

    $this->render('viewjob', array(
        'model' => $model
    ));
}
以及列出数据库中数据的相应视图:

/* 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 -->
/*我应该在这里做什么*/
查看作业
不
标题
描述
无空缺
联系电子邮件
编辑
删除

首先,您应该通过CActiveDataProvider在控制器中获取表数据。然后在视图中,您可以使用widget-CGridView。使用此小部件,您可以设置所需的参数。列、过滤器等。您也可以粘贴代码,我们将尝试解决您的问题。Yii很简单:)

在你的行动中,说出你的观点

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

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

        $this->render('viewjob', $params);
    }
将数据作为CActiveDataProvider对象获取

在模型中,创建搜索函数

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',
        ),
    ));
}
那么在你看来,

$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',
            ),
        ),
    ));

谢谢,但您的解决方案是在核心php中,我不想知道如何用yii实现。Sagi,@mitul marsonia在《非核心php》中的回答是,但它是针对yii的。使用CGridView确实是将数据打印为表格的Yii方式。crafter,我的评论是关于他之前的答案,他后来编辑了他的答案。