Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have dbtables:
- 1. Observations(id(pk), id_species(fk), date)
- 2. Species (id(pk), name, group_id(fk))
- 3. Groups (id(pk), name)
- My Models (ObservationsBirds and ObservationsMammals are only for collecting data - there are others views):
- <?php
- class ObservationsBirds extends ActiveRecord
- {
- public function tableName()
- {
- return 'Observations';
- }
- public function relations()
- {
- return array(
- 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
- );
- }
- }
- class ObservationsMammals extends ActiveRecord
- {
- public function tableName()
- {
- return 'Observations';
- }
- public function relations()
- {
- return array(
- 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
- );
- }
- }
- class AllObservations extends ActiveRecord
- {
- public function tableName()
- {
- return 'Observations';
- }
- public function relations()
- {
- return array(
- 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
- );
- }
- }
- My AllObservations Controller
- <?php
- class AllObservationsController extends Controller
- {
- public function actionAdmin()
- {
- $model=new AllObservations('search');
- $model->unsetAttributes(); // clear any default values
- if(isset($_GET['AllObservations']))
- $model->attributes=$_GET['AllObservations'];
- $this->render('admin',array(
- 'model'=>$model,
- ));
- }
- public function loadModel($id)
- {
- $model=AllObservations::model()->findByPk($id);
- if($model===null)
- throw new CHttpException(404,'The requested page does not exist.');
- return $model;
- }
- }
- My AllObservations admin view:
- <?php
- <?php $this->widget('bootstrap.widgets.TbGridView',array(
- 'dataProvider'=>$model->search(),
- 'columns'=>array(
- 'id',
- 'id_speciesr',
- array(
- 'class'=>'bootstrap.widgets.TbButtonColumn',
- 'buttons'=>array(
- 'view' => array(
- 'url'=>'Yii::app()->controller->createUrl("
- //here i have to insert link to actions, for example if this is birds observations it should be
- observationsBirds/view",array("id"=>$data[id]"))'
- //if it will be Mammals observations it should be
- observationsMammals/view",array("id"=>$data[id]"))'
- ,
- ),
- ),
- )); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement