Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search error with column type text. #85

Open
wash34000 opened this issue Jun 8, 2021 · 2 comments
Open

Search error with column type text. #85

wash34000 opened this issue Jun 8, 2021 · 2 comments

Comments

@wash34000
Copy link

Hello,

I've a problem with one table column that is a text type in my model.
When i try to search i've an error on line 311 in DataTablesComponent.php, PHP cannot set type "text" :

settype(): Invalid type [ROOT/vendor/ypnos-web/cakephp-datatables/src/Controller/Component/DataTablesComponent.php, line 311]

        $columnDesc = $table->getSchema()->getColumn($column);
        $columnType = $columnDesc['type'];
        // wrap value for LIKE and NOT LIKE
        if (strpos(strtolower($comparison), 'like') !== false) {
            $value = $this->getConfig('prefixSearch') ? "{$value}%" : "%{$value}%";

            if ($this->_table->getConnection()->getDriver() instanceof Postgres) {
                if ($columnType !== 'string' && $columnType !== 'text') {
                    $textCast = "::text";
                }
            }
        }
        settype($value, $columnType);
        $condition = ["{$table->getAlias()}.{$column}{$textCast} {$comparison}" => $value];

Can i force my text field to string without modify your controller file ?

Kind regards

@wash34000
Copy link
Author

For now i've change line 300 :

$columnType = ($columnDesc['type'] === 'text') ? 'string' : $columnDesc['type'];

@ypnos
Copy link

ypnos commented Jun 9, 2021

Instead, add this before line 311:

if ($columnType === 'text') { // convert to PHP type
    $columnType = 'string';
}

Please test it and if it works, do a pull request. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants