简体   繁体   中英

CakePHP 3: Exception not Found

I've written several placeholder functions in my User model. All I want them to do is throw the NotImplementedException() provided by CakePHP . The function is nice and simple and I have tried it several different ways.

public function canConvert() {
    throw new NotImplementedException();
}

Error:Class 'App\\Model\\Entity\\NotImplementedException' not found

public function canConvert() {
    throw new \NotImplementedException();
}

Error:Class 'NotImplementedException' not found

The only way I could find to do this was this way.

public function canConvert() {
    throw new \Cake\Network\Exception\NotImplementedException();
}

I tried to do a use Cake\\Network\\Exception; and the top and just throw a NotImplementedException() but that didn't work.

If you just do

use Cake\Network\Exception; 

you've only imported the namespace, not the classes under it. To reference a class under that namespace, you would then need to do:

throw new Exception\NotImplementedException();

PHP doesn't automatically import all classes under a namespace.

Read more in the manual: http://php.net/manual/en/language.namespaces.importing.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM