newsUpdate.php 885 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. use \app\helpers\Uuid;
  3. use manager\models\News;
  4. $this->title="Редактирование статьи";
  5. $this->params['breadcrumbs'][] = ['label' => 'Новости', 'url' => ['newslist']];
  6. $this->params['breadcrumbs'][] = $this->title;
  7. if( !isset($id) ){
  8. $request = Yii::$app->request;
  9. $id = $request->get('id');
  10. }
  11. if( !isset($model) ){
  12. $model = News::findOne($id);
  13. if( !$model ){
  14. $model = new \app\models\News();
  15. }
  16. }
  17. if( !(isset($model->uid) && $model->uid && Uuid::isvalid($model->uid)) )
  18. {
  19. if( strlen( $model->uid ) <> 32 ) //2f58b5602dc6500d645ea6032118884e old style
  20. {
  21. $i = 100;
  22. while( $i )
  23. {
  24. $uuid = Uuid::GetUUID();
  25. $model->uid = $uuid;
  26. $tmp = $model->find()->andWhere(['uid'=>$uuid])->one();
  27. if( !$tmp ) break;
  28. $i--;
  29. }
  30. }
  31. }
  32. echo $this->render('formNews', [
  33. 'news' => $model,
  34. ]);
  35. ?>