0

我使用 Yii php 框架制作了一个财务管理模块,并通过 Gii 安装了模型、控制器、CRUD 和视图。现在我想在表格中显示为每个财务运动创建的内容,每行一个运动,在视图运动页面内 - 例如在 admin.php(管理控件)中,但无法更新它们。

我对 Yii 很陌生,尽管我非常努力,但 Yii 似乎对我来说太晦涩难懂了。如何让我的 motion/views/view.php 显示一个 HTML 表格,其中包含我的移动表格中的所有条目?

- 更新:

这是_view.php的代码形式

    <?php

/* @var $this MovementController */
/* @var $data Financialmovement */

$due = gmdate( 'd/m/Y', $data->due_date );

if ( $data->pay_date != 0 ) {
    $pay = gmdate( 'd/m/Y', $data->pay_date );
} else {
    $pay = 'Indisponível';
}
switch ( $data->category ):
    case ('trn'):
        $category = "Transporte";
        break;
    case ('fin'):
        $category = "Financeiro";
        break;
    default :
        $category = 'Erro! Valor nulo.';
endswitch;

if ( $data->condition = 1 ) {
    $condition = 'Concluída';
} else {
    $condition = 'Aberta';
}

if ( $data->movement_type = 1 ) {
    $type = 'Saída';
} else {
    $type = 'Entrada';
}


$value = $data->value;
$patern = '/\./';
$replacement = ',';
$value = preg_replace( $patern, $replacement, $value );

$coin = $data->coin_type;
$patern = '/s/';
$replacement = '$';
$coin = preg_replace( $patern, $replacement, $coin );

?>

<tr class="wide form">
    <td >
        <?php echo $data->getAttributeLabel( 'id' ); ?>:
        <?php echo CHtml::link( ( $data->id ), array( 'view', 'id' => $data->id ) ); ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'category' ); ?>:
        <?php echo $category; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'value' ); ?>:
        <?php echo '<span class="capital">' . $coin . "</span> " . $value; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'due_date' ); ?>:
        <?php echo $due; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'pay_date' ); ?>:
        <?php echo $pay; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'description' ); ?>:
        <?php echo $data->description; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'condition' ); ?>:
        <?php echo $condition; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'movement_type' ); ?>:
        <?php echo $type; ?>

    </td>
    <td >
        <?php echo $data->getAttributeLabel( 'observation' ); ?>:
        <?php echo $data->observation; ?>

    </td>
</tr>

这是 view.php 的代码:

    <?php

/* @var $this MovementController */
/* @var $model Financialmovement */

$this->breadcrumbs = array(
    'Financial Movements' => array( 'index' ),
    $model->id,
);

$this->menu = array(
    array( 'label' => 'List Financial Movement', 'url' => array( 'index' ) ),
    array( 'label' => 'Create Financial Movement', 'url' => array( 'create' ) ),
    array( 'label' => 'Update Financial Movement', 'url' => array( 'update', 'id' => $model->id ) ),
    array( 'label' => 'Delete Financial Movement', 'url' => '#', 'linkOptions' => array( 'submit' => array( 'delete', 'id' => $model->id ), 'confirm' => 'Are you sure you want to delete this item?' ) ),
    array( 'label' => 'Manage Financial Movement', 'url' => array( 'admin' ) ),
);

?>

<h1>View Financial Movement #<?php echo $model->id; ?></h1>
<table>
    <tr>
        <td>Id</td>
    </tr>
    <?php

    $dataProvider = new CActiveDataProvider( 'Financialmovement' );

    $this->widget( 'zii.widgets.CListView', array(
        'dataProvider' => $dataProvider,
        'itemView' => '_view', // refers to the partial view named '_view'
        'sortableAttributes' => array(
            'id',
            'due_date',
            'pay_date',
            'category',
        ),
    ) );

    ?>
</table>
4

1 回答 1

1

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

于 2012-12-26T09:05:50.643 回答