Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model Observation:
- <?php
- class Observation extends CActiveRecord
- {
- public function relations()
- {
- return array(
- 'idCity' => array(self::BELONGS_TO, 'City', 'city_id'),
- );
- }
- }
- Controller Observation
- <?php
- class ObservationController extends Controller
- {
- public function actionCreate()
- {
- $model=new Observation;
- $commune=new Commune;
- if(isset($_POST['Observation']))
- {
- $model->attributes=$_POST['Observation'];
- $commune->attributes=$_POST['Commune'];
- if($model->save())
- $this->redirect(array('view','id'=>$model->id));
- }
- $this->render('create',array(
- 'model'=>$model,
- 'commune'=>$commune,
- ));
- }
- public function loadModel($id)
- {
- $model=Observation::model()->findByPk($id);
- if($model===null)
- throw new CHttpException(404,'The requested page does not exist.');
- return $model;
- }
- }
- View Observation (_form.php)
- <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
- 'id'=>'observation-form',
- 'enableAjaxValidation'=>false,
- 'type'=>'horizontal',
- )); ?>
- <?php echo $form->errorSummary($model); ?>
- $form->hiddenFieldRow($model,'city_id'); ?>
- $form->textFieldRow($model,'name'); ?>
- $form->textFieldRow($commune,'name',array('class'=>'span3','disabled'=>true)); ?>
- <div class="form-actions">
- <?php $this->widget('bootstrap.widgets.TbButton', array(
- 'buttonType'=>'submit',
- 'type'=>'primary',
- 'label'=>$model->isNewRecord ? 'Create' : 'Save',
- )); ?>
- </div>
- <?php $this->endWidget(); ?>
- Model City:
- <?php
- class City extends CActiveRecord
- {
- public function relations()
- {
- return array(
- 'idCommune' => array(self::BELONGS_TO, 'Commune', 'commune_id'),
- );
- }
- }
- Model Commune (standard generated model - without relations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement