Hello everyone, recently I'm working a project where F3 is used as backend. Everything working fine except an ERROR while using models (ikkez/f3-cortex).
config.ini:
DB_PATH = ../db/
...
GET /user = Controller->user
POST /save = Controller->save
index.php:
$f3 = Base::instance();
$db = new DB\Jig($f3->DB_PATH, DB\Jig::FORMAT_JSON);
$f3->set('DB', $db);
user.php (model):
use DB\Cortex;
use DB\SQL\Schema;
class User extends Cortex {
protected $table = 'users', $fieldConf = array(
'name' => array(
'type' => Schema::DT_VARCHAR256,
'validate'=> 'required|min:3'
),
'email' => array(
'type' => Schema::DT_VARCHAR128,
'validate' => 'required|unique:users'
),
'password' => array(
'type' => Schema::DT_VARCHAR256,
'validate' => 'required|min:6|confirmed'
),
'password_reset' => array(
'has-one' => array(PasswordReset::class, 'user_id')
),
'activation' => array(
'has-one' => array(Activation::class, 'user_id')
),
);
public function __construct() {
parent::__construct();
$saveHandler = function() {
// some validation
}
$this->beforesave($saveHandler);
controller.php:
class Controller {
protected $f3;
protected $model;
public function __construct() {
$this->f3 = Base::instance();
$this->model = new User();
}
public function user() {
$this->model->reset();
...
}
public function save() {
$data = $this->f3->get('POST');
// some data validation
$this->model->reset();
$this->model->copyFrom($data, array_keys($this->model->fieldConf));
$this->model->save();
}
}
With this code, both routes are ended with an "INVALID HIVE KEY NULL" error; I also tried to remove the `reset()` call from `save`, but error shifts to the `copyFrom`.
I can't understand what is wrong with this code...
So please suggest me something to overcome from this error.
Thanks & Regards