im stucked in making the trackstar app. I can’t find solutions to other sections so i decided to post it here. I hope someone helps me
Here’s my IssueController located at : /protected/controllers/IssueController.php
<?php
class IssueController extends Controller
{
/**
*@ @var private property containing the associated Project model instance.
*/
private $_project = null;
/**
* Protected method to load the associated Project model class
* @param integer projectId the primary identifier of the associated Project
* @return object the Project data model based on the primary key */
protected function loadProject($projectId) {
//if the project property is null,create it based on input Id
if($this->_project==null){
$this->_project=Project::model()->findByPk($projectId);
if($this->_project===null){
throw new CHttpException(404,'The requested project does not exist.');
}
}
return $this->_project;
}
/**
* In-class defined filter method, configured for use in the above filters()
*method. It is called before the actionCreate() action method is run in
*order to ensure a proper project context
*/
/**
*Implementing Filters
*/
public function filterProjectContext($filterChain)
{
//set the project identifier based on GET input request variables
if(isset($_GET['pid']))
$this->loadProject($_GET['pid']);
else
throw new CHttpException(403,'Must specify a project before performing this action');
//complete the running of other filters and execute the requested action
$filterChain->run();
}
/**
* @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
'projectContext + create update', // check to ensure valid project context
);
}
/**
* 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'),
'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('*'),
),
);
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Issue;
$model->project_id=$this->_project->id;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Issue']))
{
$model->attributes=$_POST['Issue'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Issue']))
{
$model->attributes=$_POST['Issue'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Issue');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Issue('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Issue']))
$model->attributes=$_GET['Issue'];
$this->render('admin',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=Issue::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']==='issue-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
the Issue View Page located at : /protected/views/issue/_form.php
There seems to be a big problem at the getUserOptions located on line 45 that indicated this:
$model->project->getUserOptions()
<?php
/* @var $this IssueController */
/* @var $model Issue */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'issue-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'description'); ?>
</div>
<?php /* form for the Type */ ?>
<div class="row">
<?php echo $form->labelEx($model,'type_id'); ?>
<?php echo $form->dropDownList($model,'type_id', $model->getTypeOptions()); ?>
<?php echo $form->error($model,'type_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'status_id'); ?>
<?php echo $form->dropDownList($model,'status_id', $model->getStatusOptions()); ?>
<?php echo $form->error($model,'status_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'owner_id'); ?>
<?php echo $form ->dropDownList($model,'owner_id',$model->project->getUserOptions()); ?>
<?php echo $form->error($model,'owner_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'requester_id'); ?>
<?php echo $form->dropDownList($model,'requester_id',$model->project->getUserOptions()); ?>
<?php echo $form->error($model,'requester_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'create_time'); ?>
<?php echo $form->textField($model,'create_time'); ?>
<?php echo $form->error($model,'create_time'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'create_user_id'); ?>
<?php echo $form->textField($model,'create_user_id'); ?>
<?php echo $form->error($model,'create_user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'update_time'); ?>
<?php echo $form->textField($model,'update_time'); ?>
<?php echo $form->error($model,'update_time'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'update_user_id'); ?>
<?php echo $form->textField($model,'update_user_id'); ?>
<?php echo $form->error($model,'update_user_id'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
and lastly heres my Issue model located at : /protected/models/Issue.php
<?php
/**
* This is the model class for table "tbl_issue".
*
* The followings are the available columns in table 'tbl_issue':
* @property integer $id
* @property string $name
* @property string $description
* @property integer $project_id
* @property integer $type_id
* @property integer $status_id
* @property integer $owner_id
* @property integer $requester_id
* @property string $create_time
* @property integer $create_user_id
* @property string $update_time
* @property integer $update_user_id
*
* The followings are the available model relations:
* @property User $requester
* @property User $owner
* @property Project $id0
*/
class Issue extends CActiveRecord
{
//add three constant definitions on Web App with Yii and PHP
const TYPE_BUG=0;
const TYPE_FEATURE=1;
const TYPE_TASK=2;
public function getProject()
{
}
/**
* Retrieves a list of issue types
* @return array an array of available issue types.
*/
public function getTypeOptions()
{
return array(
self::TYPE_BUG=>'Bug',
self::TYPE_FEATURE=>'Feature',
self::TYPE_TASK=>'Task',
);
}
//add three constant variables for status dropdowns
const STATUS_NYS=0;
const STATUS_S=1;
const STATUS_F=2;
//Retrieves a list of status types
public function getStatusOptions()
{
return array(
self::STATUS_NYS=>'Not Yet Started',
self::STATUS_S=>'Started',
self::STATUS_F=>'Finished',
);
}
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Issue 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 'tbl_issue';
}
/**
* @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('name', 'required'),
array('project_id, type_id, status_id, owner_id, requester_id, create_user_id, update_user_id', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>255),
array('description, create_time, update_time', 'safe'),
//the CRangeValidator rule for Type
array('type_id', 'in', 'range'=>self::getAllowedTypeRange()),
//the CRangeValidator rule for Status
array('type_id', 'in', 'range'=>self::getAllowedStatusRange()),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, description, project_id, type_id, status_id, owner_id, requester_id, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),
);
}
/**
*@return a method to return allowed range for type
*/
public static function getAllowedTypeRange()
{
return array(
self::STATUS_NYS,
self::STATUS_S,
self::STATUS_F,
);
}
/**
*@return a method to return allowed range for type
*/
public static function getAllowedStatusRange()
{
return array(
self::TYPE_BUG,
self::TYPE_FEATURE,
self::TYPE_TASK,
);
}
/**
* @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(
'requester' => array(self::BELONGS_TO, 'User', 'requester_id'),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),
'id0' => array(self::BELONGS_TO, 'Project', 'id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'project_id' => 'Project',
'type_id' => 'Type',
'status_id' => 'Status',
'owner_id' => 'Owner',
'requester_id' => 'Requester',
'create_time' => 'Create Time',
'create_user_id' => 'Create User',
'update_time' => 'Update Time',
'update_user_id' => 'Update User',
);
}
/**
* 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('name',$this->name,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('project_id',$this->project_id);
$criteria->compare('type_id',$this->type_id);
$criteria->compare('status_id',$this->status_id);
$criteria->compare('owner_id',$this->owner_id);
$criteria->compare('requester_id',$this->requester_id);
$criteria->compare('create_time',$this->create_time,true);
$criteria->compare('create_user_id',$this->create_user_id);
$criteria->compare('update_time',$this->update_time,true);
$criteria->compare('update_user_id',$this->update_user_id);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}