CakePHP - How can I determine the route to a non-cakephp file that does not have any controllers associated with it?

Now I work in CakePHP. I would like to know how I can determine the route to a non-cakephp file that has no controllers associated with it?

I placed this file (sitemap.php) in the webroot folder, for my convenience. Now I need to somehow route it!

+3
source share
2 answers

It looks like you want to use the functionality from the sitemap.php file in your cakephp application. The bidding method to include this in cakephp is to configure it as a provider. Follow these steps:

1- /. 2- ( ), :

App::import('Vendor','sitemap');

, , PHP. , , show_links(), , , vendor/sitemap, :

show_links();

, , :

App::import('Vendor','sitemap');
$sitemap = new Sitemap;
$sitemap->show_links();

, sitemap config/routes.php:

Router::connect('/sitemap.xml', array('controller' => 'YOUR_CONTROLLER', 'action' => 'YOUR_ACTION'));

, , sitemap.php.

, , - :

<?php
class SiteMapController extends AppController
{
  var $name = 'Tests';
  function show_map()
  {
    App::import('Vendor','sitemap');
    $sitemap = new Sitemap;
    $sitemap->show_links();
  }
}
?>

config/routes.php :

Router::connect('/sitemap.xml', array('controller' => 'site_maps', 'action' => 'show_map'));

, URL-:

http://mysite/sitemap.xml

:

http://mysite/site_maps/show_map

: http://book.cakephp.org/view/542/Defining-Routes

!

!

+2

CakePHP, . .htaccess ( , * *), sitemap.php. , .htaccess, .

, `sitemap.xml ', CakePHP, .htaccess( , , ?).

: , , CakePHP, .

+1

Source: https://habr.com/ru/post/1736122/


All Articles