There is a method that displays one news:

public function actionOne() { $id_article = $_GET['id']; $onenews = NewsModel::getOne($id_article); $view = new View(); $view->listonenews = $onenews; $view->display('adminnews/one.php'); // Здесь происходит обновление записей, данные приходят из формы $onenews->title = $_POST['title']; $onenews->date = $_POST['date']; $onenews->text = $_POST['text']; $onenews->updateNews(); } 

The problem is that the same page processes the form and, therefore, warnings are displayed on the screen, because the data from the form has not yet arrived:

Notice: Undefined index: title

and so with all the fields I'm going to update.

Please tell me how you can fix this moment.

  • Well, check through isset or empty before using $ _POST ['title'] and others, and where are all these tags about pdo / orm / ar? - kroder
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Competently split the processing and rendering of a form into different actions in one you will render the form as it is, in the other you will process the form. And you should use the methods of working with a post like getPost(),getParam() , etc. etc. used framework, or write your own method

 public function getPost($key) { if(isset($_POST[$key])) { return $_POST[$key]; } else { return null; } } 

and the form processing will look something like this

 public function actionOneSave() { $onenews->title = $this->getPost('title'); $onenews->date = $this->getPost('date'); $onenews->text = $this->getPost('text'); $onenews->updateNews(); } 
  • Thank you very much for the advice! - O.Petrov