Advertisement
Guest User

Untitled

a guest
Mar 19th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Model Observation:
  2. <?php
  3. class Observation extends CActiveRecord
  4. {
  5. public function relations()
  6. {
  7. return array(
  8. 'idCity' => array(self::BELONGS_TO, 'City', 'city_id'),
  9. );
  10. }
  11. }
  12.  
  13. Controller Observation
  14. <?php
  15. class ObservationController extends Controller
  16. {
  17. public function actionCreate()
  18. {
  19. $model=new Observation;
  20. $commune=new Commune;
  21.  
  22. if(isset($_POST['Observation']))
  23. {
  24. $model->attributes=$_POST['Observation'];
  25. $commune->attributes=$_POST['Commune'];
  26.  
  27. if($model->save())
  28. $this->redirect(array('view','id'=>$model->id));
  29. }
  30.  
  31. $this->render('create',array(
  32. 'model'=>$model,
  33. 'commune'=>$commune,
  34. ));
  35. }
  36.  
  37. public function loadModel($id)
  38. {
  39. $model=Observation::model()->findByPk($id);
  40. if($model===null)
  41. throw new CHttpException(404,'The requested page does not exist.');
  42. return $model;
  43. }
  44. }
  45.  
  46. View Observation (_form.php)
  47. <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
  48. 'id'=>'observation-form',
  49. 'enableAjaxValidation'=>false,
  50. 'type'=>'horizontal',
  51. )); ?>
  52.  
  53. <?php echo $form->errorSummary($model); ?>
  54. $form->hiddenFieldRow($model,'city_id'); ?>
  55. $form->textFieldRow($model,'name'); ?>
  56. $form->textFieldRow($commune,'name',array('class'=>'span3','disabled'=>true)); ?>
  57. <div class="form-actions">
  58. <?php $this->widget('bootstrap.widgets.TbButton', array(
  59. 'buttonType'=>'submit',
  60. 'type'=>'primary',
  61. 'label'=>$model->isNewRecord ? 'Create' : 'Save',
  62. )); ?>
  63. </div>
  64.  
  65. <?php $this->endWidget(); ?>
  66.  
  67.  
  68. Model City:
  69. <?php
  70.  
  71. class City extends CActiveRecord
  72. {
  73.  
  74. public function relations()
  75. {
  76. return array(
  77. 'idCommune' => array(self::BELONGS_TO, 'Commune', 'commune_id'),
  78. );
  79. }
  80. }
  81.  
  82. Model Commune (standard generated model - without relations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement