Advertisement
Guest User

Untitled

a guest
Apr 5th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. I have dbtables:
  2. 1. Observations(id(pk), id_species(fk), date)
  3. 2. Species (id(pk), name, group_id(fk))
  4. 3. Groups (id(pk), name)
  5.  
  6. My Models (ObservationsBirds and ObservationsMammals are only for collecting data - there are others views):
  7.  
  8. <?php
  9.  
  10. class ObservationsBirds extends ActiveRecord
  11. {
  12. public function tableName()
  13. {
  14. return 'Observations';
  15. }
  16. public function relations()
  17. {
  18. return array(
  19. 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
  20. );
  21. }
  22. }
  23.  
  24. class ObservationsMammals extends ActiveRecord
  25. {
  26. public function tableName()
  27. {
  28. return 'Observations';
  29. }
  30. public function relations()
  31. {
  32. return array(
  33. 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
  34. );
  35. }
  36. }
  37.  
  38. class AllObservations extends ActiveRecord
  39. {
  40. public function tableName()
  41. {
  42. return 'Observations';
  43. }
  44. public function relations()
  45. {
  46. return array(
  47. 'idSpecies' => array(self::BELONGS_TO, 'Species', 'id_species'),
  48. );
  49. }
  50. }
  51.  
  52. My AllObservations Controller
  53.  
  54. <?php
  55. class AllObservationsController extends Controller
  56. {
  57. public function actionAdmin()
  58. {
  59. $model=new AllObservations('search');
  60. $model->unsetAttributes(); // clear any default values
  61. if(isset($_GET['AllObservations']))
  62. $model->attributes=$_GET['AllObservations'];
  63. $this->render('admin',array(
  64. 'model'=>$model,
  65. ));
  66. }
  67.  
  68. public function loadModel($id)
  69. {
  70. $model=AllObservations::model()->findByPk($id);
  71. if($model===null)
  72. throw new CHttpException(404,'The requested page does not exist.');
  73. return $model;
  74. }
  75. }
  76.  
  77. My AllObservations admin view:
  78.  
  79. <?php
  80.  
  81. <?php $this->widget('bootstrap.widgets.TbGridView',array(
  82. 'dataProvider'=>$model->search(),
  83. 'columns'=>array(
  84. 'id',
  85. 'id_speciesr',
  86. array(
  87. 'class'=>'bootstrap.widgets.TbButtonColumn',
  88. 'buttons'=>array(
  89. 'view' => array(
  90. 'url'=>'Yii::app()->controller->createUrl("
  91. //here i have to insert link to actions, for example if this is birds observations it should be
  92. observationsBirds/view",array("id"=>$data[id]"))'
  93. //if it will be Mammals observations it should be
  94. observationsMammals/view",array("id"=>$data[id]"))'
  95. ,
  96. ),
  97. ),
  98.  
  99. )); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement