Update/Insert Form issue with CRUD


#1

Hi!
I’ve been testing ATK4 today and I really enjoy its logic, great work on it and thanks for keeping it open-source!

Now I do have an issue I haven’t been able to resolve: basically I tried to create a CRUD to edit some database table close to the quickstart example. The list of items is being correctly displayed but I can’t seem to be able to insert/update/delete items.

I opened the console on Firefox (F12) and there is the following error whenever a pop-up (for insert/update) opens:

TypeError: can't assign to property "id" on "": not an object          atkjs-ui.min.js:1:41903

This results into the pop-up displaying infinitely a loading animation but nothing more.

When deleting an item, I simply have a blank line pop-up. Any idea about what could cause this?

Here are snippets of the code:

index.php

session_start();

$app = new CustomApp('Secure_DL');
$app->initLayout('Centered');

//custom object that deals with retrieving connection info from .conf files
$db = ConnectionFactory::getFactory()->getDatabase();

$app->dbConnect(
    $db->getDSN(),
    $db->getUser(),
    $db->getPassword()
);

$crud = $app->add([
    'CRUD',
    'fieldsCreate' => ['paths','expiration_date'],
    'fieldsUpdate' => ['expiration_date', 'valid']
]);
$crud->setModel(new Link($app->db));

link.php

class Link extends \atk4\data\Model{
public $table = 'Links';

function init()
{
    parent::init();
    $this->addField('hash', [
        'type' => 'hash',
        'caption' => 'Hash'
    ]);
    $this->getElement('hash')->read_only = true;
    $this->addField('expiration_date', [
        'type' => 'date',
        'caption' => 'Expiration Date'
    ]);
    $this->addField('paths', ['caption' => 'Paths']);
    $this->addField('valid', [
        'type' => 'boolean',
        'caption' => 'Valid']);
    }
}

custom_app.php

class CustomApp extends atk4\ui\App{
public function __construct($defaults = [])
{
    $this->ui_persistence = new CustomPersistence();

    parent::__construct($defaults);
}
}

custom_persistence.php

class CustomPersistence extends\atk4\ui\Persistence\UI {
public function _typecastSaveField(\atk4\data\Field $f, $value)
{
    switch ($f->type) {
        case 'hash':
            //converts bin value to some string representation using custom alphabet
            return MD5_RawTo24($value);
    }
    return parent::_typecastSaveField($f, $value);
}
}

Any help would be most welcome :slight_smile:


#2

Can you tell if the error is caused by your implementation of hash field or it’s due to some bug in JS?


#3

I have created a new table in my db, so that the ‘hash’ field is basically just text and there is no need for the CustomePersistence. I still encounter the same issue, with the same error in the JS console so I’d say it’s a JS issue… Is there any way to get more info for you?


#4

I was able to fix my issue actually! I must have not understood something, I tried a custom implementation of a router using:

$path_str = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

And had an if-else block on the path to print various info (using echo) or display the app. I removed this part to only have the app displayed at the root and it worked! Now I have to understand how routing works with Agile Toolkit, but this should come easy with your documentation :wink:


#5

glad it worked for you!