I've recently updated my MAMP server to PHP 7.1 and build a project with Cakephp 3.x. But I get a strange 500 (Internal Server Error) error when I use the afterSave() callback.
The documentation lifecycle-callbacks describes the following:
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
// some action
}
When I use PHP 7.1 it will give's me a 500 error, but if I use PHP 5.6 it will work for me.
Now I've fixed this 500 error on PHP 7.1 by no longer defining the types inside the function. But is this the correct way to do this?
public function afterSave($event, $entity, $options) {
// some action
}
Update:
My error log says:
2017-05-06 13:38:09 Error: [TypeError] Argument 1 passed to Storages\Model\Table\StoragecontainerBlockElementsTable::afterSave() must be an instance of Storages\Model\Table\Event, instance of Cake\Event\Event given, called in /Applications/MAMP/htdocs/safebend-community-data-center/community/vendor/cakephp/cakephp/src/Event/EventManager.php on line 414 Request URL: /storages/blocks/dsdsdsd/ajaxAddElement Referer URL: http://localhost:8888/safebend-community-data-center/community/storages/blocks/dsdsdsd
My Table with namespace:
namespace Storages\Model\Table;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\ORM\TableRegistry;
class StoragecontainerBlockElementsTable extends Table {
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
// some action
}
}
My Controller with Namespace:
namespace Storages\Controller;
use App\Controller\AppController;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
class StoragecontainerBlocksController extends AppController { }