Thanks for the suggestion. i'll read up on how to do that, but don't be
surprised if i end up back here for some clarifications. But i'll give it a
try before bugging the group again. :)
-joe
On Wednesday, 23 July 2014 02:34:29 UTC-4, José Lorenzo wrote:
>
> I would use plugins for organizing them
>
> On Wednesday, July 23, 2014 5:33:18 AM UTC+2, Joe Theuerkauf wrote:
>>
>> Okay, i fixated on this tonight & i think i got it to work. i put
>> CaptchasTable back in App/Model/Table, and behold the class loads correctly
>> (i forgot to adjust the namespace in the previous message).
>>
>> However, before i do a happy dance, i'd like to know if it's *POSSIBLE*
>> to organize my Models into subdirectories as i was attempting to do:
>>
>> Model/Table/* : My project's main DB Table classes
>> Model/Table/Websites/* : Table classes from the Websites database, so
>> they're not cluttering up my project's main tables...
>> Model/Table/____/* : Similar if i need to connect to any other
>> databases...
>>
>> Can this be done at all?
>>
>>
>>
>>
>>
>> On Tuesday, 22 July 2014 21:26:20 UTC-4, Joe Theuerkauf wrote:
>>>
>>> José:
>>>
>>> Sorry for the delayed response. i've been getting burned out (and burned
>>> up with the weather), so i took a day to breathe.
>>>
>>> i called $this->Captchas->defaultConnectionName() from inside the
>>> ContactsController:
>>>
>>> public function index() {
>>> $this->loadModel('Captchas');
>>> // PS: i'm using the LogTrait in the class...
>>> $this->log('defaultConnectionName: ' .
>>> $this->Captchas->defaultConnectionName());
>>>
>>> // ...
>>> }
>>>
>>>
>>> Output in error.log:
>>>
>>> 2014-07-23 01:16:55 Error: defaultConnectionName: default
>>>
>>>
>>> Obviously, not what i was expecting. And that's the value whether i have
>>> CaptchasTable in the main Model/Table or in Model/Table/Website.
>>>
>>> If you have further suggestions, please let me know. i know 3.0 is alpha
>>> so i do expect some breakage. But when the documentation is so brief &
>>> doesn't seem to work, it can be frustrating.
>>> -joe
>>>
>>>
>>> On Monday, 21 July 2014 04:08:18 UTC-4, José Lorenzo wrote:
>>>>
>>>> what is returned if you call $this->Captchas->defaultConnectionName() ?
>>>>
>>>> On Sunday, July 20, 2014 6:29:33 PM UTC+2, Joe Theuerkauf wrote:
>>>>>
>>>>> i tried this topic before, but the only response was for an older
>>>>> version of Cake...
>>>>>
>>>>> i'm following this documentation:
>>>>>
>>>>> http://book.cakephp.org/3.0/en/orm/table-objects.html#configuring-connections
>>>>>
>>>>> i'm trying to keep a few tables that would be application-agnostic in
>>>>> a different database. i'm not trying to create associations as mentioned
>>>>> in
>>>>> #3463. i just need to query independent records from these tables.
>>>>>
>>>>> Here's what i have so far:
>>>>> // Config/app.php
>>>>> $config = [
>>>>> // ...
>>>>> 'Datasources' => [
>>>>> 'default' => [
>>>>> // Connection to this DB works.
>>>>> 'database' => 'kodiak',
>>>>> ],
>>>>> 'websites' => [
>>>>> // Connection is identical, except different 'database' value
>>>>> 'database' => 'websites',
>>>>> ]
>>>>> ]
>>>>> // ...
>>>>> ];
>>>>>
>>>>> // Model/Table/Websites/CapchasTable.php
>>>>> class CaptchasTable extends Table {
>>>>> public static function defaultConnectionName () {
>>>>> return 'websites';
>>>>> }
>>>>> }
>>>>>
>>>>> // Controller/ContactsController.php
>>>>> public function index () {
>>>>> $this->loadModel('Captchas');
>>>>>
>>>>> $captcha = $this->Captchas->find('all', [
>>>>> 'conditions' => [],
>>>>> 'order' => 'RAND()',
>>>>> 'limit' => 1
>>>>> ]);
>>>>>
>>>>> // etc.
>>>>> }
>>>>>
>>>>> Here's the error output:
>>>>>
>>>>> SQLSTATE[42S02]: Base table or view not found: 1146 Table
>>>>> *'kodiak.captchas'* doesn't exist
>>>>>
>>>>> Error: An Internal Error Has Occurred.
>>>>> Stack Trace
>>>>>
>>>>> ROOT\vendor\cakephp\cakephp\src\Database\Schema\Collection.php
>>>>> line 113 → Cake\Database\Schema\Collection->_executeSql(string, array)
>>>>> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 323 →
>>>>> Cake\Database\Schema\Collection->describe(string)
>>>>> ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 127 →
>>>>> Cake\ORM\Table->schema()
>>>>> ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 110 →
>>>>> Cake\ORM\Query->addDefaultTypes(Cake\ORM\Table)
>>>>> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 927 →
>>>>> Cake\ORM\Query->__construct(Cake\Database\Connection, Cake\ORM\Table)
>>>>> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 724 →
>>>>> Cake\ORM\Table->query()
>>>>> APP/Controller\ContactsController.php line 36 →
>>>>> Cake\ORM\Table->find(string, array)
>>>>> [internal function] → App\Controller\ContactsController->index()
>>>>> ROOT\vendor\cakephp\cakephp\src\Controller\Controller.php line 373
>>>>> → ReflectionMethod->invokeArgs(App\Controller\ContactsController, array)
>>>>> ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php line 115 →
>>>>> Cake\Controller\Controller->invokeAction()
>>>>> ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php line 87 →
>>>>> Cake\Routing\Dispatcher->_invoke(App\Controller\ContactsController)
>>>>> ROOT\webroot\index.php line 37 →
>>>>> Cake\Routing\Dispatcher->dispatch(Cake\Network\Request,
>>>>> Cake\Network\Response)
>>>>>
>>>>> It doesn't seem to matter if CaptchasTable is in Model/Table or
>>>>> Model/Table/Websites; loadModel('Captchas') doesn't throw errors
>>>>> either way. But the find() call is throwing the error - *regardless
>>>>> where *CaptchasTable* is placed*. When it's commented, the page loads
>>>>> fine (since i'm hitting this error, i haven't actually tried to USE any
>>>>> of
>>>>> the Captcha data in my form yet).
>>>>>
>>>>> So the question is: why isn't defaultConnectionName setting up the
>>>>> connection to the `websites` DB? What's missing? Is it missing
>>>>> documentation & i need to do something more, or is this a bug?
>>>>>
>>>>> i'd appreciate any help before i post this to the Github issues.
>>>>> Thanks.
>>>>>
>>>>>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.