*sigh* i guess i still need help here, but with the routing, not the DB 
connection.

i want to preserve the original way i was accessing my general-purpose 
Controller: /captchas/whatever.

i'm generally confused by routing, but AM reading the docs trying to figure 
it out. i know i *don't* want to use /thook/websites/captchas to get to 
this Controller. It's just a validation AJAX call, and besides, having the 
extra path segments in there feels awkward to me.

Trying to follow these:
http://book.cakephp.org/3.0/en/plugins.html#plugin-configuration
http://book.cakephp.org/3.0/en/plugins.html#plugin-controllers
http://book.cakephp.org/3.0/en/development/routing.html#plugin-routing

i've enabled the plugin's 'routes' option in *bootstrap.php* 
Plugin::loadAll() and i have this in my *plugin*'s *routes.php*:
Route::plugin('Thook/Websites', function($routes) {
    $routes->fallbacks();
});

i also tried adding this to the *App/Config/routes.php*:
Routes::scope('/', function($routes) {
// ... other routes
    $routes->connect('/captchas', ['plugin' => 'Thook/Websites']);
// ... some other routes
});

i'm unable to get the message described in the docs (Model not found) when 
i go to the intended URL. Instead i get Controller not found 
(App\Controller\ThookController).

i'll keep trying, but anything toward helping me understand this better 
would be hugely appreciated.
-joe


On Saturday, 30 August 2014 01:04:22 UTC-4, Joe Theuerkauf wrote:
>
> i wasn't. My mistake. However, i guess there was more to the puzzle. Even 
> after adding Plugin::loadAll() to bootstrap.php, it wasn't working.
>
> i continued to tinker, finally creating a full-blown plugin (*cake bake 
> plugin Thook/Websites*). Note the original post was just the Model 
> commands - i hadn't created the plugin before hand.
>
> i had to make some adjustments to namespaces and the composer.json path 
> strings. It's writing ./plugins/... instead of ./Plugin where bake actually 
> places the plugin's directory tree, and path separators are getting mixed 
> up. If you want more detail on that, i'll create a dummy plugin & note the 
> mix-ups. Yes, it's Windows... ;-)
>
> Whatever i did this time, it's working. i've confirmed by pulling out all 
> the old
>
> i don't know if it's because i'm switching between Cake 3 on this project 
> and Zend 1 at work, or what, but my brain is pudding. 
>
> Any idea how to get my IDE (PhpStorm) to recognize the namespaces 
> correctly, since the *src/* part of the path breaks up the PSR-0/4 
> conformity? Just curious. The app functions
>
> Now to work on hooking up the routes & controllers...
>
> Congrats on getting to beta, by the way!
> -joe
>
>
>
> On Friday, 29 August 2014 04:00:35 UTC-4, José Lorenzo wrote:
>>
>> How did you load your plugin?
>>
>> On Friday, August 29, 2014 9:32:48 AM UTC+2, Joe Theuerkauf wrote:
>>>
>>> A while ago i created this thread: 
>>> https://groups.google.com/forum/#!topic/cake-php/A5WHkiWCPd4
>>>
>>> i was trying to hook up tables from a second database, using a different 
>>> Datasource connection from *app.php*.
>>>
>>> My default is "kodiak", the other is "websites". It's a general-use set 
>>> of tables, like MimeTypes, Captcha questions, etc.
>>>
>>> i got them working by putting them in together with Table/Entity classes 
>>> from the "kodiak" database. However, i wanted to organize the class files 
>>> for these Tables/Entities away from the other stuff, and the suggestion was 
>>> to use a Plugin syntax.
>>>
>>> Cut to tonight:
>>>
>>> 1. i used the cake command line to build models within my plugin:
>>>
>>>
>>>
>>> *cake bake model Thook\Websites.Captchas --connection=websites*2. The 
>>> files were built successfully within *Plugin/Thook/Websites/src*.
>>>
>>> 3. i added
>>>
>>>
>>>
>>> *public static function defaultConnectionName() {    return 'websites';}*to 
>>> each of the Table classes i built, as i had done originally under 
>>> *App/Model/Table*. i kinda feel this part should be added automatically 
>>> if *--connection* is specified on the command line, but the point is 
>>> moot.
>>>
>>> 4. i changed the line in my Controller that loads the Captchas Model 
>>> (per http://book.cakephp.org/3.0/en/plugins.html#plugin-models at the 
>>> end of that section):
>>>
>>> *$captchasTable = TableRegistry::get('Thook/Websites.Captchas');*
>>> i think that's the right syntax. If i try anything else similar to it, i 
>>> get class-not-found errors.
>>>
>>> Using that syntax, i get this:
>>>
>>>
>>> *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 
>>> 116 → Cake\Database\Schema\Collection->_reflect(string, string, array, 
>>> Cake\Database\Schema\Table)
>>>     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 136 → 
>>> Cake\ORM\Table->schema()
>>>     ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 119 → 
>>> 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 65 → 
>>> Cake\ORM\Table->find(string)
>>> (expanded...)
>>>          $termsTable = TableRegistry::get('Terms');
>>>          $captchasTable = TableRegistry::get('Thook/Websites.Captchas');
>>>
>>> *Line 65: $captcha = $captchasTable->find('random')->first();*
>>> So it brings me back to the same thing i was struggling with last time: 
>>> it looks like the Table class gets loaded, but *defaultConnectionName* 
>>> isn't doing its job to tell the App to use the 'websites' connection 
>>> instead of 'default' (kodiak). 
>>>
>>> *find('random')* is in a Table extension class i added, and was also 
>>> working until i started trying the Plugin approach for the Model.
>>>
>>> Any help?
>>>
>>>

-- 
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.

Reply via email to