0
votes

I have made a module for financial management using Yii php framework and installed the model, controller, CRUD , and views through Gii. Now I want to display the contents created for each financial movement in a table , one movement per row, inside the view movements page - such as in the admin.php (the manage control), but without the ability to update them.

I'm very new to Yii and, even though I tried very hard, Yii seems to be too obscure for me to achieve anything. How can I make my movement/views/view.php display a HTML table with the all the entries from my movement table?

--UPDATE:

Here is the code form _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>

Here is the code for 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>
1
echo the data and check in what format it is available on view page and set the html view according to that - hemc4
w00t do not put logic in your view, that's ugly - Asgaroth

1 Answers

1
votes

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 :)