Error: "Invalid hive key NULL" (using Model - ikkez/f3-cortex)

97 views
Skip to first unread message

Anu Tig3r

unread,
Oct 12, 2017, 9:25:16 AM10/12/17
to Fat-Free Framework
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
Message has been deleted

xfra35

unread,
Oct 12, 2017, 1:40:02 PM10/12/17
to Fat-Free Framework
Judging from the source code, it shouldn't be a problem to pass an array.

ved

unread,
Oct 12, 2017, 1:55:28 PM10/12/17
to Fat-Free Framework
Oops, you're right. I've deleted the post since it was clearly wrong and served no purpose.
In fact, even F3 seems to also allow external arrays on copyfrom. (which I also did not know).
Sorry about the confusion op.
Reply all
Reply to author
Forward
0 new messages