I am new to cakephp 3.2 I have saved data by calling model in cakephp 2X version in this way.
$this->Schools->add_school($schools);
I have used the same in 3x,but it not working showing Unknown method "add_school"
I have defined the function in model also
below is model code School.php
School.php
<?php
namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
class School extends Entity
{
public function add_school($schools) {
echo "hii";exit;
}
}
error is showing Unknown method "add_school" Please suggest me. Thank you in advance.
Simple typo - $this->Schools
is wrong - class School
should be called as $this->School->
Edit: Why is someone downvoting all answers?
your writing code is right becouse your code have mistek which is yes used this only one mistek "s"
$this->School->add_school($schools);
You need to study the docs a little more closely, you are mixing up entities and tables. The former represent data, and the latter are used for interacting with the database.
Your custom method should go into your SchoolsTable
class (in src/Model/Table
), then, given that $this->Schools
exists (you may need to use $this->loadModel('Schools'))
, you can call your method via that reference.
See