Cakephp: Argument 1 passed to Cake\ORM\Table::save() must implement interface Cake\Datasource\EntityInterface, array given, called in /opt/lampp/htdocs/billingcake/src/Controller/BillsController.php on line 48

Created on 6 Apr 2017  路  2Comments  路  Source: cakephp/cakephp

Hi all, I am facing issue and my code are below.Please help me how can i fixed that issue...

<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\ORM\Table;
use Cake\Event\Event;
use Cake\ORM\Query;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use App\Model\Entity\Role;
use Cake\Datasource\ConnectionManager;
use Cake\View\Helper\HtmlHelper;
use Cake\View\View;
use Cake\Core\Configure;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
use Cake\Collection\Collection;


use Faker;


class BillsController extends AppController
{

    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('RequestHandler');
    }

    public function index(){


      $bill = $this->Bills->newEntity();

      if ($this->request->is('post')) {
            $bill = $this->Bills->patchEntity($bill, $this->request->data);
            $bill = $this->request->data('product_id');


           $products = TableRegistry::get('Products');
            $query = $products->find('list');

            $bill = $query->toArray();


            if ($this->Bills->save($bill)) {

              $this->Flash->success(__('The billNo has been saved.'));

              return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The billNo could not be saved. Please, try again.'));
        }
        $this->set(compact('bill'));
        $this->set('_serialize', ['bill']);





}
}
?>
invalid

Most helpful comment

As for your exception: The message is very clear on that one, please read it, compare the method expectation with what you pass, read the docs and you will most certainly figure it out.

All 2 comments

Looks like you should review the blog tutorial as your code is fundamentally different - as is apparent from the error you receive.

This is not a help forum. The ticket tracker is reserved for possible
bugs and feature enhancements to the CakePHP framework. If you are
looking for help on how to implement a feature or to better understand
how to use the framework correctly, please visit one of the following:

The CakePHP Manual
The CakePHP online API
CakePHP Official Forum
Stackoverflow
Slack channel

or the #cakephp channel on irc.freenode.net, where we will be more than
happy to help answer your questions.

Thanks!

As for your exception: The message is very clear on that one, please read it, compare the method expectation with what you pass, read the docs and you will most certainly figure it out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cleptric picture cleptric  路  3Comments

GBeushausen picture GBeushausen  路  3Comments

Erwane picture Erwane  路  3Comments

Code-Working picture Code-Working  路  3Comments

thinkingmedia picture thinkingmedia  路  3Comments