CakePHP - 通过 bootstrap.php 访问数据库
你能帮助我如何使用 cakephp 的 bootstrap.php 文件访问数据库吗?
tnx 广告!
更新:我真正的问题是:
关于 url,我如何使用不同的路由定义。
IE。我可以(我不知道如何)菜单不同的网址,例如:
http://example.com/contents
http://example.com/kind
http://example.com/article
http://example.com/quote
http://example.com/master
等等
我会在数据库中定义所有这些网址。
那么,实现这一目标的最佳方法是什么?我是否需要在routes.php 文件中进行数据库连接和查询,或者有更好的方法来实现这一点。
can you help me how to access database using cakephp's bootstrap.php file?
tnx in adv!
UPDATE: my real question is next:
how can i use different route definition, regarding url.
ie. i can have (i don't know how) menu different urls, like:
http://example.com/contents
http://example.com/kind
http://example.com/article
http://example.com/quote
http://example.com/master
etc etc
i would define all those urls in database.
so, which is best way to achieve this? do i need to have db connection and query in routes.php file, or there is better way to achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,不需要,而且此时您不应该对数据库执行任何操作。
只需定义一个路由,将所有
/*
URL 发送到特定控制器:然后在您的
FoosController
中,您可以进行搜索:请了解有关路由的更多信息:http://book.cakephp.org/view/945/Routes-Configuration
No, you don't, and you're not supposed to do anything with the database at this point.
Just define a route that will send all
/*
URLs to a specific controller:Then in your
FoosController
, you can do a search:Please, learn more about routing: http://book.cakephp.org/view/945/Routes-Configuration
您不需要在数据库中保存该路由,您需要保存 url“菜单项”。忘记将所有内容路由到 /* 的想法,这是一个可怕的黑客行为。不过,您确实需要了解有关路由的更多信息。可以将路由保存到数据库,如下所示 https://github.com/infinitas /infinitas/tree/dev/core/routes
you dont need to save that route in the db, you need to save the url 'menu item'. forget the idea about routing everything to /* that is a horrible hack. you do need to learn more about routing though. Saving routes to the database is possible as seen here https://github.com/infinitas/infinitas/tree/dev/core/routes