Re: 3.x: Same Behaviour for Multiple Tables
ha, rightthanks :-) using namespace App\Model\Behavior; solved the problem! Am Dienstag, 29. Juli 2014 04:33:38 UTC+2 schrieb euromark: > > Why are you using > > namespace Cake\Model\Behavior; > > in your behavior? > The namespace should cleary be App\... > > mark > > > Am Montag, 28. Juli 2014 15:43:35 UTC+2 schrieb Bernhard Minatti: >> >> Hello! >> >> I'm trying to add the same behaviour to multiple Tables, which are >> related to each other. Thus i created a class "SpecialBehaviour", which is >> included in both Tables in their initialize() method: >> $this->addBehavior('SpecialBehaviour'); >> >> It works fine, when only one of the tables is queried, but when executing >> a Query that joins the two tables together, an error is thrown: >> *Cannot redeclare class Cake\Model\Behavior\SpecialBehavior* >> >> Is there another way to add a global behavior to multiple tables? >> >> thanks in advance! >> > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
Why are you using namespace Cake\Model\Behavior; in your behavior? The namespace should cleary be App\... mark Am Montag, 28. Juli 2014 15:43:35 UTC+2 schrieb Bernhard Minatti: > > Hello! > > I'm trying to add the same behaviour to multiple Tables, which are related > to each other. Thus i created a class "SpecialBehaviour", which is included > in both Tables in their initialize() method: > $this->addBehavior('SpecialBehaviour'); > > It works fine, when only one of the tables is queried, but when executing > a Query that joins the two tables together, an error is thrown: > *Cannot redeclare class Cake\Model\Behavior\SpecialBehavior* > > Is there another way to add a global behavior to multiple tables? > > thanks in advance! > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
Just a crazy idea, can you verify that in all places you have used the same casing? For example in some places you may have used 'sites' whereas in others 'Sites', there migh be a bug around using different casing there. On Monday, July 28, 2014 9:13:15 PM UTC+2, Bernhard Minatti wrote: > > hmmm... > > stackTrace() does not output anything, but using debug_print_backtrace() i > get: > > #0 include() called at > [/Applications/MAMP/htdocs/vendor/composer/ClassLoader.php:382] > #1 > Composer\Autoload\includeFile(/Applications/MAMP/htdocs/src/Model/Behavior/SpecialBehavior.php) > called at [/Applications/MAMP/htdocs/vendor/composer/ClassLoader.php:274] > #2 > Composer\Autoload\ClassLoader->loadClass(App\Model\Behavior\SpecialBehavior) > #3 spl_autoload_call(App\Model\Behavior\SpecialBehavior) > #4 class_exists(App\Model\Behavior\SpecialBehavior) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/Core/App.php:113] > #5 Cake\Core\App::_classExistsInBase(\Model\Behavior\SpecialBehavior, App) > called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/Core/App.php:91] > #6 Cake\Core\App::className(Special, Model/Behavior, Behavior) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/ORM/BehaviorRegistry.php:74] > #7 Cake\ORM\BehaviorRegistry->_resolveClassName(Special) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/Utility/ObjectRegistry.php:74] > #8 Cake\Utility\ObjectRegistry->load(Special, Array ()) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/ORM/Table.php:490] > #9 Cake\ORM\Table->addBehavior(Special) called at > [/Applications/MAMP/htdocs/src/Model/Table/SitesTable.php:12] > #10 App\Model\Table\SitesTable->initialize(Array ([alias] => > Sites,[className] => App\Model\Table\SitesTable,[connection] => > Cake\Database\Connection Object ([] => Array ([driver] => > Cake\Database\Driver\Mysql,[persistent] => ,[host] => localhost,[login] => > root,[password] => root,[database] => hometeam,[prefix] => ,[encoding] => > utf8,[timezone] => UTC,[log] => ,[cacheMetadata] => 1,[name] => default),[] > => Cake\Database\Driver\Mysql Object ([] => Array ([persistent] => 1,[host] > => localhost,[login] => root,[password] => ,[database] => cake,[port] => > 3306,[flags] => Array (),[encoding] => utf8,[timezone] => ,[init] => Array > (),[dsn] => ),[] => Array ([driver] => > Cake\Database\Driver\Mysql,[persistent] => ,[host] => localhost,[login] => > root,[password] => root,[database] => hometeam,[prefix] => ,[encoding] => > utf8,[timezone] => UTC,[log] => ,[cacheMetadata] => 1,[name] => > default,[port] => 3306,[flags] => Array (),[init] => Array (),[dsn] => ),[] > => ,[] => `,[] => `,[] => ,[] => ),[] => 0,[] => ,[] => ,[] => ,[] => ))) > called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/ORM/Table.php:216] > #11 Cake\ORM\Table->__construct(Array ([alias] => Sites,[className] => > App\Model\Table\SitesTable,[connection] => Cake\Database\Connection Object > ([] => Array ([driver] => Cake\Database\Driver\Mysql,[persistent] => ,[host] > => localhost,[login] => root,[password] => root,[database] => > hometeam,[prefix] => ,[encoding] => utf8,[timezone] => UTC,[log] => > ,[cacheMetadata] => 1,[name] => default),[] => Cake\Database\Driver\Mysql > Object ([] => Array ([persistent] => 1,[host] => localhost,[login] => > root,[password] => ,[database] => cake,[port] => 3306,[flags] => Array > (),[encoding] => utf8,[timezone] => ,[init] => Array (),[dsn] => ),[] => > Array ([driver] => Cake\Database\Driver\Mysql,[persistent] => ,[host] => > localhost,[login] => root,[password] => root,[database] => hometeam,[prefix] > => ,[encoding] => utf8,[timezone] => UTC,[log] => ,[cacheMetadata] => > 1,[name] => default,[port] => 3306,[flags] => Array (),[init] => Array > (),[dsn] => ),[] => ,[] => `,[] => `,[] => ,[] => ),[] => 0,[] => ,[] => ,[] > => ,[] => ))) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/ORM/TableRegistry.php:166] > #12 Cake\ORM\TableRegistry::get(Sites) called at > [/Applications/MAMP/htdocs/vendor/cakephp/cakephp/src/Model/ModelAwareTrait.php:95] > #13 Cake\Controller\Controller->loadModel(Sites) called at > [/Applications/MAMP/htdocs/src/Controller/CategoriesController.php:16] > #14 App\Controller\CategoriesController->add() > #15 ReflectionMethod->invokeArgs(App\Controller\CategoriesController Object > ([helpers] => Array ([Form] => Array ([className] => > BootstrapForm),[BootstrapHTML] => ),[components] => Array ([Flash] => > ,[Session] => ,[Auth] => Array ([loginRedirect] => Array ([controller] => > Users,[action] => index),[logoutRedirect] => Array ([controller] => > Pages,[action] => display,[0] => home)),[Acl] => ),[name] => > Categories,[request] => Cake\Network\Request Object ([params] => Array > ([plugin] => ,[controller] => Categories,[action] => add,[_ext] => ,[pass] => > Array ()),[data] => Array (),[query] => Array (),[cookies] => Array >
Re: 3.x: Same Behaviour for Multiple Tables
Hmm, that's very odd. Can you add a die(stackTrace()); at the top of that file after the namespace declaration? Also try looking for the string 'SpecialBehavior' in your project, there must be another class with that same name that you are loading somehow. On Monday, July 28, 2014 8:16:08 PM UTC+2, Bernhard Minatti wrote: > > the error is as follows: > [28-Jul-2014 16:14:06 UTC] PHP Fatal error: Cannot redeclare class > Cake\Model\Behavior\SpecialBehavior in > /Applications/MAMP/htdocs/hometeam/src/Model/Behavior/SpecialBehavior.php > on line 38 > > this comes directy from the php error log, cakephp itself does not log > anything. > > Am Montag, 28. Juli 2014 19:02:38 UTC+2 schrieb José Lorenzo: >> >> Can you also paste the full error you are getting? > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
the error is as follows: [28-Jul-2014 16:14:06 UTC] PHP Fatal error: Cannot redeclare class Cake\Model\Behavior\SpecialBehavior in /Applications/MAMP/htdocs/hometeam/src/Model/Behavior/SpecialBehavior.php on line 38 this comes directy from the php error log, cakephp itself does not log anything. Am Montag, 28. Juli 2014 19:02:38 UTC+2 schrieb José Lorenzo: > > Can you also paste the full error you are getting? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
Can you also paste the full error you are getting? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
my files are as follows: src/Model/Behavior/SpecialBehavior.php namespace Cake\Model\Behavior; use Cake\Event\Event; use Cake\ORM\Behavior; use Cake\ORM\Query; use Cake\Network\Request; use Cake\Network\Session; use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\Controller\Component\AuthComponent; class SpecialBehavior extends Behavior { public function beforeFind(Event $event, $query) { //do stuff } } src/Model/Table/SitesTable.php addBehavior('Site'); $this->addBehavior('Special'); } } src/Model/Table/CategoriesTable.php addBehavior('Special'); } public function validationDefault(Validator $validator) { return $validator ->notEmpty('name', 'A name is required'); } } thanks in advance! Am Montag, 28. Juli 2014 16:02:03 UTC+2 schrieb José Lorenzo: > > Can you show where you created that behavior class?. It would be nice if > you can gist your Tables as well > > On Monday, July 28, 2014 3:43:35 PM UTC+2, Bernhard Minatti wrote: >> >> Hello! >> >> I'm trying to add the same behaviour to multiple Tables, which are >> related to each other. Thus i created a class "SpecialBehaviour", which is >> included in both Tables in their initialize() method: >> $this->addBehavior('SpecialBehaviour'); >> >> It works fine, when only one of the tables is queried, but when executing >> a Query that joins the two tables together, an error is thrown: >> *Cannot redeclare class Cake\Model\Behavior\SpecialBehavior* >> >> Is there another way to add a global behavior to multiple tables? >> >> thanks in advance! >> > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: 3.x: Same Behaviour for Multiple Tables
Can you show where you created that behavior class?. It would be nice if you can gist your Tables as well On Monday, July 28, 2014 3:43:35 PM UTC+2, Bernhard Minatti wrote: > > Hello! > > I'm trying to add the same behaviour to multiple Tables, which are related > to each other. Thus i created a class "SpecialBehaviour", which is included > in both Tables in their initialize() method: > $this->addBehavior('SpecialBehaviour'); > > It works fine, when only one of the tables is queried, but when executing > a Query that joins the two tables together, an error is thrown: > *Cannot redeclare class Cake\Model\Behavior\SpecialBehavior* > > Is there another way to add a global behavior to multiple tables? > > thanks in advance! > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.