Advertisement
Guest User

Untitled

a guest
May 6th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. class NewsService extends Model {
  2.  
  3. /**
  4. * @param commonmodelsNews
  5. */
  6. private $_newsModel;
  7.  
  8. /**
  9. * NewsService constructor.
  10. * @param array $config
  11. */
  12. public function __construct($config = []) {
  13.  
  14. parent::__construct($config);
  15.  
  16. if(isset($config['id']) && $config['id']) {
  17. $this->_newsModel = News::findOne($config['id']);
  18. $this->setAttributes($this->_newsModel->getAttributes());
  19. }
  20. else {
  21. $this->_newsModel = new News();
  22. }
  23. }
  24.  
  25. public function rules()
  26. {
  27. return $this->_newsModel->rules();
  28. }
  29.  
  30. public function attributeLabels()
  31. {
  32. return $this->_newsModel->attributeLabels();
  33. }
  34.  
  35. public function actionCreate()
  36. {
  37. $model = new NewsService();
  38.  
  39. if (Yii::$app->request->isPost && $model->validate()) {
  40. $model->save();
  41. return $this->redirect(['view', 'id' => $model->id]);
  42. }
  43.  
  44. return $this->render('create', ['model' => $model]);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement