-2

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.

Siguza
  • 21,155
  • 6
  • 52
  • 89
user198003
  • 11,029
  • 28
  • 94
  • 152
  • Sorry, what? What is it you want to do? – deceze Jan 24 '11 at 23:42
  • i want to execute some sql queries, and they shoud be defined and executed in bootstrap.php – user198003 Jan 25 '11 at 06:39
  • 2
    that is very bad practice. Your bootstrap sets up the environment, you should try and follow an MVC pattern and run your queries from your models, and of course the models from your controllers. you can find out more about MVC – cromestant Jan 25 '11 at 09:13
  • ok, but, how can i use different routes for different kind of url, when relation between url and routes is defined in database? – user198003 Jan 25 '11 at 09:29
  • 1
    I don't know why you'd want to "define relation between url and routes in the database", that's a weird and nonsensical thing to do. Look at my answer for how this kind of thing is usually handled. If this is not satisfactory, describe what's in your database and what you want to do. – deceze Jan 25 '11 at 09:36

2 Answers2

2

do i need to have db connection and query in routes.php file[?]

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:

Router::connect('/:category', array('controller' => 'foos', 'action' => 'bar'));

Then in your FoosController, you can do a search:

function bar() {
    $category = $this->Foo->find('first', array(
        'conditions' => array('Foo.name' => $this->params['named']['category'])
    ));
    ...
}

Please, learn more about routing: http://book.cakephp.org/view/945/Routes-Configuration

deceze
  • 510,633
  • 85
  • 743
  • 889
0

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

dogmatic69
  • 7,574
  • 4
  • 31
  • 49