Trying to understand cortex...

68 views
Skip to first unread message

v.

unread,
May 11, 2018, 10:04:23 AM5/11/18
to f3-fra...@googlegroups.com
Hi,

I am trying to understand the much discussed Cortex plugin.
I am playing around with it a little bit but I am somewhat confused.

I have a model 'User' and a controller, aptly named 'UserController'.
I have found out the possibility to use the fluid mode from the controller, this seems to be working, except that I think I found a bug: when the db table 'users' does not yet exist the program generates an error on the rights_level item. It does not appear to be accepting the underscore, without the underscore in the model it works.
    public function index()
   
{
        $user
->name="admin";
        $user
->mail="te...@mail.inv";
        $user
->website="www.google.com";
        $user
->rights_level=1;
        $user
->save();
        $user
->reset();
        $this
->f3->set('users',$user->all());
        $this
->f3->set('view','list.htm');
   
}
My User model:
class User extends \DB\Cortex {

 
protected
    $fieldConf
= array(
       
'name' => array(
           
'type' => 'VARCHAR256',
           
'nullable' => false,
       
),
       
'mail' => array(
           
'type' => 'VARCHAR128'
       
),
       
'website' => array(
           
'type' => 'VARCHAR256'
       
),
       
'rights_level' => array(
           
'type' => 'TINYINT',
           
'default' => 3,
       
),
   
),
    $db
= 'DB',
    $table
= 'users',
    $fluid
= true,      // triggers the SQL Fluid Mode, default: false
    $primary
= 'uid',   // name of the primary key (auto-created), default: id
    $ttl
= 120,         // caching time of field schema, default: 60
    $rel_ttl
= 30;      // caching time of all relations, default: 0
   
   
public function all()
   
{
       
return $this->find();
   
}
}
This is code I copied from the cortex manual on github.

I do not understand how to set the $db in the model. If I sent it from the controller (as above) the model seems to be using that db and it does not take the one set as $db into account.
I only need to set the $table, that is the only thing it seems to care about.
If I don't send the db-connection in the controller it never gets set. How can I set the DB variable that is being used in the sample code?
This is likely also linked to the fact that I can not user $user::setup() to initialize the table.

edit: removed the edit....

ikkez

unread,
May 12, 2018, 4:38:06 AM5/12/18
to Fat-Free Framework
Well this

$db = 'DB'

means it'll look in the F3 hive key DB for a DB instance. So $f3->set('DB', $db); will solve this. Alternatively you can instantiate the object with $db as first constructor parameter.
And to install the model before instantiating the class, use User::setup() instead of $user::setup()

Reply all
Reply to author
Forward
0 new messages