Jump to content

When use $page->path and $page->url


clsource
 Share

Recommended Posts

Plase correct me if something is wrong, I'm still learning the processwire way xd.

According to the API Docs

http://processwire.com/api/variables/page/

$page->path

The page's URL path from the homepage (i.e. /about/staff/ryan/)

$page->url

The page's URL path from the server's document root (may be the same as the $page->path)

So I have to migrate a site from development to production server and all the links were messed up.

Why?

Because I was using $page->path for redirects. Changed redirects to $page->url and Presto! everything works fine.

And, When to use $page->path?

Use $page->path when importing other page.

example

$people = $pages->get('/system/people');

$friend = $pages->get($people->path . $input->urlSegment1);
 

Use $page->url when you need a redirect

$session->redirect($friend->url);
 
  • Like 2
Link to comment
Share on other sites

You'll also get errors when you use $config->paths->root in images etc (500 i believe) but if you use $config->urls->root you'll get away with it. I believe there's a different way of approaching things. Not sure why, never really looked into it but if someone is able and willing to explain that would be nice!

  • Like 1
Link to comment
Share on other sites

$config->paths->[property] refers to the server disk paths, and $config->urls->[property] refers to the corresponding URL. 

A Page object is something represented in a database, not a disk path on the server. So you can't draw a literal relationship between server paths and a page, since there is no physical file or directory for a page. Where you can draw the relationship is that the term 'path' or 'paths' always refers to the internal, server-side representation. Whereas the term 'url' or 'urls' always refers to to the external, client-side representation (something you would deliver to the browser). 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...