Sou iniciante no yii. Estou fazendo um aplicativo de gestão de telecentros e tenho um model aluno e um arquivo certificado. O que quero é que a partir da view de um determinado aluno eu clique em um link e abra o arquivo de certificado já com o nome do aluno mostrado na view. Pegue o nome do aluno e jogue no certificado. Como faço isso? Da forma como está ai aparece o erro: Error 400 Sua requisição é inválida.
3479
certificado ---------------------------------------
<?php
/* @var $this AlunoController */
/* @var $model Aluno */
$this->breadcrumbs=array(
'Alunos'=>array('index'),
$model->id=>array('view','id'=>$model->id),
'Certificado',
);?>
<div id="certificado">
<?php //$lista = CHtml::listData(Usuario::model()->findAll(), 'id', 'nome');
echo "<div id='image1'>".CHtml::image(Yii::app()->baseUrl.'/images/mc.jpg', 'certificado', array('align'=>'letf', 'width'=>'128', 'height'=>'128'))."</div>";
echo "<div id='image2'>".CHtml::image(Yii::app()->baseUrl.'/images/telecentro.jpg', 'certificado', array('align'=>'letf', 'width'=>'128', 'height'=>'128'))."</div>";
echo "<div id='head'><h1>Certificado de Conclusão de Curso</h1></div></br></br></br>".
"<p id='texto'>Certificamos para os devidos fins que o(a) aluno(a)";
echo $model->usuario0->nome."conclui o curso básico de informática, com carga horaria de 45 horas,".
"no período de ____/____/______ a ____/____/______.</p></br></br>".
"<p id='data'>Parnaíba ".date(d)."/".date(m)."/".date(Y).".</p>".
"<center>__________________________________</center>".
"<center></center><p>Instrutor responsável.</p></center>";
?>
<!-- <center><?php echo CHtml::image(Yii::app()->baseUrl.'/images/certificado.png', 'certificado', array('align'=>'letf', 'width'=>'800', 'height'=>'600')); ?></center> -->
</div>
model aluno---------------------------------
<?php
/**
* This is the model class for table "aluno".
*
* The followings are the available columns in table 'aluno':
* @property integer $id
* @property integer $turma
* @property integer $usuario
* @property integer $catpublico
* @property integer $escola
* @property string $turno
* @property string $serie
* @property integer $situa_escolar
*
* The followings are the available model relations:
* @property Sitescolar $situaEscolar
* @property Catpublico $catpublico0
* @property Escola $escola0
* @property Turma $turma0
* @property Usuario $usuario0
* @property Frequencia[] $frequencias
* @property Turno $turno0
* @property Serie $serie0
*/
class Aluno extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Aluno the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'aluno';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('turma, usuario, catpublico, escola, situa_escolar', 'numerical', 'integerOnly'=>true),
array('turno, serie', 'length', 'max'=>50),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, turma, usuario, catpublico, escola, turno, serie, situa_escolar', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'situaEscolar' => array(self::BELONGS_TO, 'Sitescolar', 'situa_escolar'),
'catpublico0' => array(self::BELONGS_TO, 'Catpublico', 'catpublico'),
'escola0' => array(self::BELONGS_TO, 'Escola', 'escola'),
'turma0' => array(self::BELONGS_TO, 'Turma', 'turma'),
'turno0' => array(self::BELONGS_TO, 'Turno', 'turno'),
'usuario0' => array(self::BELONGS_TO, 'Usuario', 'usuario'),
'serie0' => array(self::BELONGS_TO, 'Serie', 'serie'),
'frequencias' => array(self::MANY_MANY, 'Frequencia', 'frequencia_aluno(Aluno_id, Frequencia_id)'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'turma' => 'Turma',
'usuario' => 'Usuario',
'catpublico' => 'Catpublico',
'escola' => 'Escola',
'turno' => 'Turno',
'serie' => 'Serie',
'situa_escolar' => 'Situacao Escolar',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('turma',$this->turma);
$criteria->compare('usuario',$this->usuario);
$criteria->compare('catpublico',$this->catpublico);
$criteria->compare('escola',$this->escola);
$criteria->compare('turno',$this->turno,true);
$criteria->compare('serie',$this->serie,true);
$criteria->compare('situa_escolar',$this->situa_escolar);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
alunocontroller ---------------------------
<?php
class AlunoController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','frequencia'),
'users'=>array('*'),
),
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','certificado'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionCertificado($id)
{
$model=$this->loadModel($id);
$this->render('certificado',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Aluno::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='aluno-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
De já agradeço a quem ajudar-me!