Re: Solution for static page with no "pages" in URL

2009-01-20 Thread Gonzalo Servat
On Tue, Jan 20, 2009 at 4:39 PM, teknoid  wrote:

>
> This is a simple solution, that I prefer.
>
> I ensure that all links to static pages point to .html file
>
> So our link:
> www.example.com/pages/about_us
>
> Becomes:
> www.example.com/about_us.html (i.e. echo $thml->link('About Us', '/
> about_us.html'); )
>
> Then a single route takes care of the rest (for any static page on
> your site):
>
> Router::connect('/(.*).html', array('controller' => 'pages', 'action'
> => 'display'));
>

Nice. Thanks teknoid :)

- Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread teknoid

This is a simple solution, that I prefer.

I ensure that all links to static pages point to .html file

So our link:
www.example.com/pages/about_us

Becomes:
www.example.com/about_us.html (i.e. echo $thml->link('About Us', '/
about_us.html'); )

Then a single route takes care of the rest (for any static page on
your site):

Router::connect(’/(.*).html’, array(’controller’ => ‘pages’, ‘action’
=> ‘display’));


On Jan 20, 1:32 pm, "Jon Bennett"  wrote:
> Hi leo,
>
> >  And that is what it does. Go tohttp://univerd.com/mantenimiento-jardin
> >  . That is a pages page. Nothing is specifically defined for that page.
>
> ok - but how!? the routes you provided do not have an asterix after
> the first trailing slash, so how is cake getting the value from the
> url passed as a param?
>
> confused :/
>
> j
>
> --
>
> jon bennett
> w:http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread Jon Bennett

Hi leo,

>  And that is what it does. Go to http://univerd.com/mantenimiento-jardin
>  . That is a pages page. Nothing is specifically defined for that page.

ok - but how!? the routes you provided do not have an asterix after
the first trailing slash, so how is cake getting the value from the
url passed as a param?

confused :/

j

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread leo

And that is what it does. Go to http://univerd.com/mantenimiento-jardin
. That is a pages page. Nothing is specifically defined for that page.

On Jan 20, 7:00 pm, "Jon Bennett"  wrote:
> Hi Leo,
>
> >  Router::connect('/pages/*', array('controller' => 'pages', 'action'
> >  => 'display'));
>
> It's the above route he's trying to avoid. He wants to have:
>
> Router::connect('/*', array('controller' => 'pages', 'action'=> 'display'));
>
> but you can't do that unless you create a route for all your
> controllers/actions, as this overrides them all. Hence the need to
> create a route for each page via the component.
>
> cheers,
>
> Jon
>
> --
>
> jon bennett
> w:http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread Gonzalo Servat
On Tue, Jan 20, 2009 at 4:00 PM, Jon Bennett  wrote:

>
> Hi Leo,
>
> >  Router::connect('/pages/*', array('controller' => 'pages', 'action'
> >  => 'display'));
>
> It's the above route he's trying to avoid. He wants to have:
>
> Router::connect('/*', array('controller' => 'pages', 'action'=>
> 'display'));
>
> but you can't do that unless you create a route for all your
> controllers/actions, as this overrides them all. Hence the need to
> create a route for each page via the component.
>

Thank you, Jon. That's exactly right. I can't imagine we are the only ones
who want this sort of functionality !? I would much rather think about
implementing some sort of "default route" functionality into the Router
class. The current quick-and-dirty solution by Jesse isn't too bad, I guess.

- Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread Jon Bennett

Hi Leo,

>  Router::connect('/pages/*', array('controller' => 'pages', 'action'
>  => 'display'));

It's the above route he's trying to avoid. He wants to have:

Router::connect('/*', array('controller' => 'pages', 'action'=> 'display'));

but you can't do that unless you create a route for all your
controllers/actions, as this overrides them all. Hence the need to
create a route for each page via the component.

cheers,

Jon


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread leo

This fragment from PagesController::display() handles specific
actions:

<--snip-->
  $path = func_get_args();

  // Clumsy, but I couldn't find a better solutio in the time
available.
  if(end($path) == 'SendEmail')
  {
$this->SendEmail();
exit();
  }
  if(end($path) == 'Something')
  {
$this->setAction('Something');
exit();
  }
  if (!count($path))
<--snip-->

The last lines of router.php look like this:

 * ...and connect the rest of 'Pages' controller's urls.
 */
Router::connect('/pages/*', array('controller' => 'pages', 'action'
=> 'display'));
Router::connect('/', array('controller' => 'portal', 'action' =>
'index', 'home'));

All the other controllers behave as expected.

It works. The website is http://www.univerd.com  (it's in Catalan/
Spanish)(and I didn't do the visual design)

On Jan 19, 10:36 pm, Gonzalo Servat  wrote:
> On Mon, Jan 19, 2009 at 7:21 PM, leo  wrote:
>
> > Ahh..you didn't say that. Seems to me all you need to do is put the
> > pages in ..er.. pages and make sure that the pages route is last in
> > the routes.php file. That way everything that has a home will find it
> > and the rest falls through to pages. No lookup for page names needed.
> > You might even be able to do a Router::connect('/*',..
>
> This isn't quite what I need as it makes any request for /controller/action
> also go to the pages controller (which is great for static pages but not if
> you have some non-static pages in controllers). If you managed to do it, I'd
> love to see your solution.
>
> - Gonzalo
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-20 Thread Jesse

I like all the suggestions you guys made. These are the  suggestions I
was looking for!

I'll take these into consideration and work on it a little. I like the
idea of dropping things into bootstrap to automatically be run.

I'll put something up in the next couple days.

-Jesse

On Jan 19, 3:36 pm, Gonzalo Servat  wrote:
> On Mon, Jan 19, 2009 at 7:21 PM, leo  wrote:
>
> > Ahh..you didn't say that. Seems to me all you need to do is put the
> > pages in ..er.. pages and make sure that the pages route is last in
> > the routes.php file. That way everything that has a home will find it
> > and the rest falls through to pages. No lookup for page names needed.
> > You might even be able to do a Router::connect('/*',..
>
> This isn't quite what I need as it makes any request for /controller/action
> also go to the pages controller (which is great for static pages but not if
> you have some non-static pages in controllers). If you managed to do it, I'd
> love to see your solution.
>
> - Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Gonzalo Servat
On Mon, Jan 19, 2009 at 7:21 PM, leo  wrote:

>
> Ahh..you didn't say that. Seems to me all you need to do is put the
> pages in ..er.. pages and make sure that the pages route is last in
> the routes.php file. That way everything that has a home will find it
> and the rest falls through to pages. No lookup for page names needed.
> You might even be able to do a Router::connect('/*',..
>

This isn't quite what I need as it makes any request for /controller/action
also go to the pages controller (which is great for static pages but not if
you have some non-static pages in controllers). If you managed to do it, I'd
love to see your solution.

- Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread leo

Ahh..you didn't say that. Seems to me all you need to do is put the
pages in ..er.. pages and make sure that the pages route is last in
the routes.php file. That way everything that has a home will find it
and the rest falls through to pages. No lookup for page names needed.
You might even be able to do a Router::connect('/*',..

I've done something like this before, I just can't access the code.

On Jan 19, 9:50 pm, Gonzalo Servat  wrote:
> On Mon, Jan 19, 2009 at 6:48 PM, leo  wrote:
>
> > 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.
>
> That means I can't take advantage of the CakePHP helpers and such ...
> besides, if they go in webroot, that means the layout won't apply so I think
> they need to go through CakePHP in my case.
>
> - Gonzalo
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Jon Bennett

hi Jesse,

>  I was looking for a way to circumvent putting a "Router::connect"
>  for each static page I have. Some of my sites have 100-150 static
>  pages. I'm looking for a way to dynamically build the routes for all
>  the pages.
>
>  My script I wrote does work, I was just looking for input from others
>  on ways to optimize my code a little, or to make sure I was using best
>  practices.

I like the idea, certainly very handy. That coupled with Gonzalo's
default route idea would make things really good. Some things I'd look
at to make things more cakey

1. Use cake's Folder class to obtain the files
2. Use App::import('component', 'PagesRoutesConfig'); // off top of
head, might be wrong!
3. What about making it work for dynamic pages as well? using
ClassRegistry::init('Page') in your component to get items from the
database
3a. If you do the above, you'll need to watch for duplicates

hth

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Jon Bennett

hi Jesse,

>  I was looking for a way to circumvent putting a "Router::connect"
>  for each static page I have. Some of my sites have 100-150 static
>  pages. I'm looking for a way to dynamically build the routes for all
>  the pages.
>
>  My script I wrote does work, I was just looking for input from others
>  on ways to optimize my code a little, or to make sure I was using best
>  practices.

One other thing, as Router:: is a static class, you should be able to
create the routes from within the component.

Also, perhaps, although this is routing related, this should be done
in bootstrap instead?

hth,

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Gonzalo Servat
On Mon, Jan 19, 2009 at 6:48 PM, leo  wrote:

>
> 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.
>

That means I can't take advantage of the CakePHP helpers and such ...
besides, if they go in webroot, that means the layout won't apply so I think
they need to go through CakePHP in my case.

- Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread leo

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?)
>
> 
> 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 "Pages";
> print_r($this->pages);
> echo "";
>
> echo "Directories";
> print_r($this->dirs);
> echo "";
>
> echo "Deleted Directories";
> print_r($this->deleted_dirs);
> echo "";
> }
> }
>
> ?>
>
>
> 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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Gonzalo Servat
On Mon, Jan 19, 2009 at 6:09 PM, Jesse  wrote:

>
> Thanks both of you for your input.
>
> All my mod_rewrite stuff is working properly.
>
> I was looking for a way to circumvent putting a "Router::connect"
> for each static page I have. Some of my sites have 100-150 static
> pages. I'm looking for a way to dynamically build the routes for all
> the pages.
>
> My script I wrote does work, I was just looking for input from others
> on ways to optimize my code a little, or to make sure I was using best
> practices.
>

I think what would be nice is a way to set a "default" route so that if all
standard routing fails, go off into a default route which would check if the
requested page exists in app/views/pages in which case it would call the
pages controller. If it doesn't exist, it could go on with the standard
"page not found" procedure.
Has anyone done this before or has a better solution in mind?

- Gonzalo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Solution for static page with no "pages" in URL

2009-01-19 Thread Jesse

Thanks both of you for your input.

All my mod_rewrite stuff is working properly.

I was looking for a way to circumvent putting a "Router::connect"
for each static page I have. Some of my sites have 100-150 static
pages. I'm looking for a way to dynamically build the routes for all
the pages.

My script I wrote does work, I was just looking for input from others
on ways to optimize my code a little, or to make sure I was using best
practices.

-Jesse

On Jan 16, 5:38 pm, brian  wrote:
> In addition to clarkphp's comment, if you have static files inside
> directories, ie. views/pages/about/foo.ctp
>
> Router::connect('/about', array('controller' => 'pages', 'action' =>
> 'display', 'about/index'));
> Router::connect('/about/*', array('controller' => 'pages', 'action' =>
> 'display', 'about'));
>
> On Fri, Jan 16, 2009 at 4:01 PM, clarkphp  wrote:
>
> > Jesse,
> > Are you wanting to access static pages without seeing the word "pages"
> > in the URL?
> > You could edit app/config/routes.php to have lines like this in it:
>
> > Router::connect('/about', array('controller' => 'pages', 'action' =>
> > 'display', 'about'));
> > Router::connect('/join', array('controller' => 'pages', 'action' =>
> > 'display', 'join'));
>
> > Then if someone accesses your site withhttp://yoursite/aboutthey see
> > the page at app/views/pages/about.php
> > An access usinghttp://yoursite/joinwould display the join page at
> > app/views/pages/join.php
>
> > Are you using mod_rewrite in Apache?  Or am I completely missing your
> > intentions?
> > - Clark
>
> > On Jan 16, 10:19 am, 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?)
>
> >> 
> >> 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 "Pages";
> >>         print_r($this->pages);
> >>         echo "";
>
> >>         echo "Directories";
> >>         print_r($this->dirs);
> >>         echo "";
>
> >>         echo "Deleted Directories";
> >>         pri

Re: Solution for static page with no "pages" in URL

2009-01-16 Thread brian

In addition to clarkphp's comment, if you have static files inside
directories, ie. views/pages/about/foo.ctp

Router::connect('/about', array('controller' => 'pages', 'action' =>
'display', 'about/index'));
Router::connect('/about/*', array('controller' => 'pages', 'action' =>
'display', 'about'));

On Fri, Jan 16, 2009 at 4:01 PM, clarkphp  wrote:
>
> Jesse,
> Are you wanting to access static pages without seeing the word "pages"
> in the URL?
> You could edit app/config/routes.php to have lines like this in it:
>
> Router::connect('/about', array('controller' => 'pages', 'action' =>
> 'display', 'about'));
> Router::connect('/join', array('controller' => 'pages', 'action' =>
> 'display', 'join'));
>
> Then if someone accesses your site with http://yoursite/about they see
> the page at app/views/pages/about.php
> An access using http://yoursite/join would display the join page at
> app/views/pages/join.php
>
> Are you using mod_rewrite in Apache?  Or am I completely missing your
> intentions?
> - Clark
>
> On Jan 16, 10:19 am, 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?)
>>
>> >
>> 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 "Pages";
>> print_r($this->pages);
>> echo "";
>>
>> echo "Directories";
>> print_r($this->dirs);
>> echo "";
>>
>> echo "Deleted Directories";
>> print_r($this->deleted_dirs);
>> echo "";
>> }
>>
>> }
>>
>> ?>
>>
>> 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 i

Re: Solution for static page with no "pages" in URL

2009-01-16 Thread clarkphp

Jesse,
Are you wanting to access static pages without seeing the word "pages"
in the URL?
You could edit app/config/routes.php to have lines like this in it:

Router::connect('/about', array('controller' => 'pages', 'action' =>
'display', 'about'));
Router::connect('/join', array('controller' => 'pages', 'action' =>
'display', 'join'));

Then if someone accesses your site with http://yoursite/about they see
the page at app/views/pages/about.php
An access using http://yoursite/join would display the join page at
app/views/pages/join.php

Are you using mod_rewrite in Apache?  Or am I completely missing your
intentions?
- Clark

On Jan 16, 10:19 am, 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?)
>
> 
> 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 "Pages";
>         print_r($this->pages);
>         echo "";
>
>         echo "Directories";
>         print_r($this->dirs);
>         echo "";
>
>         echo "Deleted Directories";
>         print_r($this->deleted_dirs);
>         echo "";
>     }
>
> }
>
> ?>
>
> 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
-~--~~~---

Solution for static page with no "pages" in URL

2009-01-16 Thread Jesse

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?)

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 "Pages";
print_r($this->pages);
echo "";

echo "Directories";
print_r($this->dirs);
echo "";

echo "Deleted Directories";
print_r($this->deleted_dirs);
echo "";
}
}

?>


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
-~--~~~~--~~--~--~---