Sunday, November 2, 2014

Re: Conditionally set defaultConnectionName

Sorry, what i meant was, i don't plan to use defaultConnectionName the same WAY i was using it for the Captcha question. If it's a legit option, i'll use it, but i see your point about not using defaultConnectionName AND a connection alias.

On Sunday, 2 November 2014 10:40:20 UTC-5, Joe Theuerkauf wrote:
Thanks for that tip, Mark. i don't plan to use defaultConnectionName in this scenario (as i did for the Captcha thread where the table i needed is in a different database).

i can see where aliasing the connection will make it hard to access the original connection. Which is why i asked for some elaboration on how/where it's used. If it can be done during the request life cycle (i.e. Controllers), i could set the alias just for the Admin-level controllers, where they WILL need the elevated permissions. The general-level controllers would never see the alias (i think). But if the alias can't be used that way, maybe it's the wrong solution.

Is it possible/reasonable to use defaultConnectionName with some conditional logic to return which connection should be used?

public function defaultConnectionName() {
    return $adminIsLoggedIn ? 'admin' : 'default';
}

If that's a reasonable approach, how can i determine $adminIsLoggedIn from inside the Table(s)? Maybe the whole question is clumsy and/or unnecessary to start with. :)

Thanks again.
-joe


On Sunday, 2 November 2014 06:48:30 UTC-5, mark_story wrote:
If you alias connections you don't need to use defaultConnectionName(). Aliasing the connection makes it much harder to access the regular default connection as whenever you ask for it you get the admin connection instead.

-mark

--
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+unsubscribe@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.

No comments: