ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

DataTables Stops Working after Upgrading CakePHP 3.6 - 3.7 #78

Closed dividedbynothing closed 4 years ago

dividedbynothing commented 4 years ago

Hello,

I've just upgraded CakePHP 3.6.7 to 3.7.9. After solving some CakePHP deprecations, everything in my app is working fine.

However, DataTables has stopped working. In the pre-upgrade (cakePHP 3.6.7) it works perfectly. After upgrading to 3.7.9, I only see the search form inputs, and no data at all.

I got the latest update of DataTables with composer require ypnos-web/cakephp-datatables:^3.0.

Looking at the browser console, I see these Errors on the page with Datatables: TypeError: g is undefinedbootstrap.min.js:6:2564 <anonymous> http://localhost/myapp/js/bootstrap.min.js:6 <anonymous> http://localhost/myapp/js/bootstrap.min.js:6 <anonymous> http://localhost/myapp/js/bootstrap.min.js:6

ReferenceError: jQuery is not defineddataTables.bootstrap.min.js:5:141 <anonymous> http://localhost/myapp/js/dataTables.bootstrap.min.js:5 <anonymous> http://localhost/myapp/js/dataTables.bootstrap.min.js:5

Loading failed for the <script> with source “http://localhost/myapp/js/DataTables.cakephp.dataTables.js”.

ReferenceError: dt is not definedmypagecontroller:126:1 <anonymous> http://localhost/myapp/mypagecontroller:126

If you have any advice on how to address these issues after my upgrade, that would be great.

Please let me know if you would like any more information.

Thanks! DBN

ypnos-web commented 4 years ago

It seems like something is wrong with the JS assets. Ensure that links to JQuery and DataTables scripts are embedded early enough in your HTML.

dividedbynothing commented 4 years ago

Hi,

Yes, for some reason after upgrading, CakePHP 3.6 to 3.7, CakePHP isn't loading 'DataTables.cakephp.dataTables.js'.

If I copy that file from the myapp\vendor\ypnos-web\cakephp-datatables\webroot to my own app's webroot\js, then load it as just 'cakephp.dataTables.js', everything works again.

I'm not sure about the exact root cause, but there is something different between the way CakePHP is loading plugins in 3.7 vs 3.6 (which is noted in your installation steps.)

Anyway, it's back to working, so at least I got that going for me.

I'm on a path to migrate to CakePHP 4. Do you foresee any issues with this in CakePHP 4?

Thanks and have a great day! DBN

ypnos-web commented 4 years ago

I went through the CakePHP 4 migration guide and I didn't spot anything particular. In any case it would be something minor.

You might need to make some changes to your code which are not directly related to this plugin but relevant. Like controlling the serialization of view variables, _serialize is deprecated and you would need to migrate your use of it (as per the quick start guide) according to the migration guide.

dividedbynothing commented 4 years ago

Thanks,

Yes, I'm planning to clear a lot of deprecations before going to 4.

In any case, I'll let you know if there's any serious issue. Cheers, DBN