I'm doing an application with Yii Framework which is relatively simple.
First I made a view called total.php
, which asks for a data inicial
, data final
and a button:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id'=>'impressoes-do-usuario-form-teste3-form',
'enableAjaxValidation'=>false,
));
?>
<div class="wide form">
<?php echo $form->labelEx($model,'dataInicio'); ?>
<?php $this->widget('CMaskedTextField', array(
'mask'=>'99-99-9999',
'model'=>$model,
'attribute'=>'dataInicio',
'value' => (empty($model->dataInicio) ? $model->dataInicio : '31/03/1987'),
));?>
</div>
<div class="wide form">
<?php echo $form->labelEx($model,'dataFim'); ?>
<?php $this->widget('CMaskedTextField', array(
'mask'=>'99-99-9999',
'model'=>$model,
'attribute'=>'dataFim'
));?>
<div class="row buttons">
<?php echo CHtml::submitButton('OK');?>
</div>
<?php $this->endWidget(); ?>
My controller is JobsLogController
, and action is actionTotal
:
<?php
class JobsLogController extends Controller
{
public $layout='//layouts/column2';
public $defaultAction = "total";
public function actionTotal()
{
$model = new ImpressoesDoUsuarioForm;
$impressoras = null;
if (isset($_POST['ImpressoesDoUsuarioForm']))
{
$model->attributes=$_POST['ImpressoesDoUsuarioForm'];
// CONVERTENDO AS DATAS
$dataInicio = Yii::app()->dateFormatter->format('yyyy-MM-dd HH:mm:ss', strtotime($model->dataInicio));
$dataFim = Yii::app()->dateFormatter->format('yyyy-MM-dd HH:mm:ss', strtotime($model->dataFim));
// BUSCA POR TODAS AS IMPRESSORAS NA DATA ESCOLHIDA
$criteria = new CDbCriteria;
$criteria->select='printer';
$criteria->distinct=true;
$criteria->condition='date>:dataInicio AND date<:dataFim';
$criteria->params=array(":dataInicio"=>$dataInicio,":dataFim"=>$dataFim);
$printers = JobsLog::model()->findAll($criteria);
array_multisort($printers,SORT_ASC);
$impressoras = array();
// BUSCA IMPRESSOES DO USUARIO NA IMPRESSORA
foreach($printers as $printer)
{
$criteria = new CDbCriteria;
$criteria->select='user';
$criteria->distinct=true;
$criteria->condition='printer=:printer AND date>:dataInicio AND date<:dataFim';
$criteria->params=array(":printer"=>$printer->printer,
":dataInicio"=>$dataInicio,
":dataFim"=>$dataFim);
$users = JobsLog::model()->findAll($criteria);
$impressoes = array();
foreach($users as $user)
{
$criteria->select='*';
$criteria->condition='user=:user AND printer=:impressora AND date>:dataInicio AND date<:dataFim';
$criteria->params=array(":user"=>$user->user,
":impressora"=>$printer->printer,
":dataInicio"=>$dataInicio,
"dataFim"=>$dataFim);
$impressoesDoUsuario = JobsLog::model()->findAll($criteria);
$contagem = 0;
foreach($impressoesDoUsuario as $impressaoDoUsuario)
{
$contagem += $impressaoDoUsuario->copies * $impressaoDoUsuario->pages;
}
$impressoes[$user->user] = $contagem;
}
$impressoras[$printer->printer] = $impressoes;
}
}
$this->render('total',array("model"=>$model,"impressoras"=>$impressoras));
}
}
?>
My problem is that I do not know how to call the action actionTotal
through the button I created in total.php
. Does anyone know how I do this in this framework? I looked in the documentation, but I did not succeed.
Thank you!