Are your static pages html or PHP? Either way, why can't you just put
them in webroot? They only need to be inside the cake structure if
they're cake files.

Jesse wrote:
> I know this comes up a lot. I've always fixed this before (1.1) with a
> core hack. I thought that as I moved my sites to 1.2 now I would come
> up with a little better solution.
>
> I'm not sure if this is the best solution but it works for me. I want
> others thoughts and opinions for this solution.
>
> THE BASICS:
> Use a class within the routes config to pull all files from the "view/
> pages" directory. Loop through this to account for directories and
> such. Store these in array (do a little hygiene). Then, loop through
> this array and create a custom route for each page.
>
> It works for me, but I am still thinking there is a better way of
> integrating this into cake. I'll provide the code I'm using on my dev
> box below. Any suggestions are welcome....
>
> /////Component that does all the work....... (should this not be a
> component?)
>
> <?php
>
> class PagesRoutesConfigComponent extends Object {
>     var $default_dir;
>     var $pages;
>     var $dirs;
>     var $deleted_dirs;
>
>     function __construct(){
>         $this->default_dir = '/users/jesseainskeep/sites/inskeep-
> photography/app/views/pages/';
>         $this->pages = array();
>         $this->dirs = array();
>         $this->deleted_dirs = array();
>
>         //run through default directory
>         $this->getPagesFromDir($this->default_dir);
>
>         //funny way or writing this... this populates the pages array
> and jumps through each directory it sees
>         $exit = true;
>         while ($exit){
>             //run through array...
>             foreach ($this->dirs as $key=>$value){
>                 $value = $value . "/";
>                 $this->getPagesFromDir($value);
>                 $this->deleted_dirs[] = $value;
>                 unset($this->dirs[$key]);
>             }
>
>             if (empty($this->dirs)){
>                 $exit = false;
>             }
>         }
>
>         //kill the full path attached to each "page"
>         foreach ($this->pages as $key=>$value){
>             $this->pages[$key] = str_replace($this->default_dir, '',
> $value);
>         }
>
>
>     }
>
>
>     function getPagesFromDir($sentDir){
>         $search = array('.ctp', '.thtml');
>         $replace = '';
>         if (is_dir($sentDir)) {
>         if ($dh = opendir($sentDir)) {
>             while (($file = readdir($dh)) !== false) {
>                 if (is_file($sentDir . $file)){
>                     $file = str_replace($search, $replace, $file);
>                     $this->pages[] = $sentDir . $file;
>                 }elseif(is_dir($sentDir . $file) && $file != "." &&
> $file != ".." ){
>                     $this->dirs[] = $sentDir . $file;
>                 }
>             }
>             closedir($dh);
>             }else{
>                 echo "Cannot open sent 'dir'!";
>             }
>         }else{
>             echo "Sent 'dir' not available!";
>
>         }
>     }
>
>     function printAll(){
>         echo "<h1>Pages</h1>";
>         print_r($this->pages);
>         echo "<br /><br />";
>
>         echo "<h1>Directories</h1>";
>         print_r($this->dirs);
>         echo "<br /><br />";
>
>         echo "<h1>Deleted Directories</h1>";
>         print_r($this->deleted_dirs);
>         echo "<br /><br />";
>     }
> }
>
> ?>
>
>
> ////Code in routes file...
> //read all files in pages directory and create custom route for each
> one
>     include_once('/users/jesseainskeep/sites/inskeep-photography/app/
> controllers/components/pages_routes_config.php');
>     $worker = new PagesRoutesConfigComponent();
>     foreach ($worker->pages as $page){
>         Router::connect($page, array('controller' => 'pages', 'action'
> => 'display', ltrim($page, '/')));
>
>     }
>
> As I said, this is my first stab and there will for sure need to be
> revisions (dynamically pulling Cake path, auto loading component vs.
> doing include, ect).
>
> This works good on my machine, but I'm sure there are problems.
> Suggestions welcome!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to