Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NewsService extends Model {
- /**
- * @param commonmodelsNews
- */
- private $_newsModel;
- /**
- * NewsService constructor.
- * @param array $config
- */
- public function __construct($config = []) {
- parent::__construct($config);
- if(isset($config['id']) && $config['id']) {
- $this->_newsModel = News::findOne($config['id']);
- $this->setAttributes($this->_newsModel->getAttributes());
- }
- else {
- $this->_newsModel = new News();
- }
- }
- public function rules()
- {
- return $this->_newsModel->rules();
- }
- public function attributeLabels()
- {
- return $this->_newsModel->attributeLabels();
- }
- public function actionCreate()
- {
- $model = new NewsService();
- if (Yii::$app->request->isPost && $model->validate()) {
- $model->save();
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('create', ['model' => $model]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement