2

We are using cakePHP 2.7.x.

The question I have is with overriding a core class -- or specifically adding functionality to a method without modifying the core code.

I need to add some functionality to the method: cake/lib/Cake/Model/Datasource/DboSource->BuildColumn()

The docs say to put the whole class in the same location under app, and then the App loader will load it. So I copied the class to marketplace/Model/Datasource/DboSource and added my code snippet. Unfortunately nothing has changed.

If I add my change directly to the original method, everything works fine.

Context: Inside that method all default values are quoted indiscriminately. Therefore something like DEFAULT CURRENT_TIMESTAMP is interpreted and run as DEFAULT 'CURRENT_TIMESTAMP' which obviously doesn't work as intended. Specifically it is giving me the error "Syntax error or access violation: 1067 Invalid default value for 'created'" when trying to cake bake a fixture.

I was directed to the cause of the problem, and a suggested fix for cakePHP 1.2.6, here: http://mamchenkov.net/wordpress/2010/04/21/unit-tests-with-cakephp/

Fliggerty
  • 73
  • 7

2 Answers2

1

According to the docs:

You can override almost every class in the framework, exceptions are the App and Configure classes. Whenever you like to perform such overriding, just add your class to your app/Lib folder mimicking the internal structure of the framework

So the path should be marketplace/Lib/Model/Datasource/DboSource, not marketplace/Model/Datasource/DboSource

Bruno Ferreira
  • 1,621
  • 12
  • 19
  • Thanks for the input. I have changed the path, however the results are still the same. Do I need to modify the new DboSource file at all? – Fliggerty Jan 26 '17 at 20:08
  • I just checked this, copied the DboSource from the `lib/Cake/Model/Datasource/DboSource.php` into `app/Lib/Model/Datasource/DboSource.php`, included a simple `die("test")` by the beggining of the file, and it was called. Are you sure your file structure is correct? – Bruno Ferreira Jan 26 '17 at 20:25
  • Very odd indeed. I have just tried the same thing, adding `die("test");` in the first line of the constructor. It wasn't called at all. I suspect then that something is wrong/different with our specific instance of cake. – Fliggerty Jan 26 '17 at 20:44
0

So apparently there was something up with my vagrant machine. After I restarted that, doing just as Bruno Ferriera outlined works perfectly!

Fliggerty
  • 73
  • 7