Welcome Guest, Not a member yet? Register   Sign In
hasChanged not working
#1

I just display the form and press enter without making any changes.

CodeIgniter\Database\Exceptions\DataException
There is no data to update.

Code:
$model = new \App\Models\PageModel;

        $id = $this->request->getPost('id');

        $page = $this->getRecordOr404($id);
        $page->fill($this->request->getPost());

        if (!$page->hasChanged()) {

            return redirect()->back()
                ->with('warning', 'Nothing to update')
                ->withInput();
        }

$model->save($page));
Reply
#2

Hi, I had a similar problem. This was my problem and my solution; https://stackoverflow.com/questions/67747865/codeigniter-4-haschanged-i-was-expecting-no-change-but-haschanged-returns
Hope this may help you.
Reply
#3

(03-10-2022, 08:43 PM)spreaderman Wrote: Hi, I had a similar problem.  This was my problem and my solution;  https://stackoverflow.com/questions/67747865/codeigniter-4-haschanged-i-was-expecting-no-change-but-haschanged-returns 
  Hope this may help you.

Thank you
Reply
#4

I had to remove the fill method for this to work with summernote.

Code:
$data = $this->request->getPost();

//$page->fill($this->request->getPost());

and change to assign each post.

Code:
$page->title = $data['title'];

        $page->zone = $data['zone'];

        $page->content = $data['content'];

        $page->active = $data['active'];

if (!$page->hasChanged()) {
Reply
#5

(This post was last modified: 03-12-2022, 12:25 PM by iRedds.)

(03-12-2022, 12:00 PM)frocco Wrote: I had to remove the fill method for this to work with summernote.

Code:
$data = $this->request->getPost();

//$page->fill($this->request->getPost());

and change to assign each post.

Code:
$page->title = $data['title'];

        $page->zone = $data['zone'];

        $page->content = $data['content'];

        $page->active = $data['active'];

if (!$page->hasChanged()) {

You can use an array of keys
PHP Code:
$page->fill($this->request->getPost(['title''zone''...etc'])); 
Reply
#6

>>You can use an array of keys<<
Thank you, I did not know that.
This resolves the error.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB