예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Activity();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Activity'])) {
         $model->attributes = $_POST['Activity'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->activity_id));
         }
     }
     if (isset($_POST['ActivityForm']) || isset($_GET['activity_id'])) {
         if (!Yii::app()->user->isGuest) {
             if (isset($_POST['ActivityForm']) && $_POST['ActivityForm']['activity_id'] == 0) {
                 $model->attributes = $_POST['ActivityForm'];
                 $model->author_id = Yii::app()->user->getId();
                 $model->save();
                 $activity_id = $model->activity_id;
             } elseif (isset($_GET['activity_id'])) {
                 $activity_id = $_GET['activity_id'];
             } else {
                 $activity_id = $_POST['ActivityForm']['activity_id'];
             }
             $link = new ActivityUser();
             $link->activity_id = $activity_id;
             $link->user_id = Yii::app()->user->getId();
             if (!$link->save()) {
                 CVarDumper::dump($link->getErrors(), 10, true);
                 exit;
             }
         }
         //			if ($model->save())
         $this->redirect(array('site/index'));
     }
     $this->render('create', array('model' => $model));
 }
예제 #2
0
    $this->widget('bootstrap.widgets.BootButton', array('buttonType' => 'submit', 'icon' => 'plus', 'label' => 'Сохранить'));
    ?>
	</div>

	<?php 
    $this->endWidget();
    ?>


<h2>Мои активности</h2>
<table width="100%">
<?php 
    $criteria = new CDbCriteria();
    //$criteria->join="LEFT JOIN activities ON t.user_id=activities.author_id ";
    $criteria->condition = "user_id=" . Yii::app()->user->id;
    $activities = ActivityUser::model()->findAll($criteria);
    foreach ($activities as $activity) {
        ?>
	<tr>
		<td width="50" nowrap>
			<?php 
        echo $activity->create_time;
        ?>
		</td>
		<td>
			<?php 
        echo CHtml::link($activity->user->username, array("user/profile", "id" => $activity->user->user_id));
        ?>
:

			<?php