How does Concrete5 arrange it's absolute paths

2019-07-31 15:12发布

I've been asked to figure out how the Concrete5 system works for an employer, and I can't figure something out.

I have Concrete5 installed to a directory on the server called /realprofessionals. When the Concrete5 system makes new pages, it gives them their own absolute paths, for instance:

http://www.wmcpartners.com/realprofessionals/footer

However, it hasn't actually made a folder in the /realprofessionals directory called footer. So how does that work? How can http://www.wmcpartners.com/realprofessionals/footer be a working link?

2条回答
Fickle 薄情
2楼-- · 2019-07-31 15:37

Short answer: All page requests are actually going through the one and only index.php file. Page content is stored in the database, not in files on the server.

Long answer: Concrete5 (and most PHP-based CMS's for that matter) work like this: all requests are routed through the index.php file. This routing is enforced with some mod_rewrite rules in the .htaccess file. The rules say "for any request, don't actually go to that page, but instead go to index.php and pass the rest of the requested path as $_GET parameters". Then in the index.php code (or some other code that is included by the index.php file), the requested page is determined based on the path that was put into the $_GET parameters by Apache (as per the mod_rewrite rule in .htaccess), and the appropriate content is retrieved from the database.

Storing content in the database as opposed to files on the server has several advantages. For example, you can re-use the same html template -- header, footer, sidebar -- on every page, and if you change the template it will automatically be reflected on all pages it's used on. Also, it makes it easier to shuffle pages around and to give them whatever URL you want (e.g. no ".php" extension at the end, or /2010/11/date/based/paths/for/blog/posts).

The disadvantage of course is that every request requires many database queries, but for most sites (those without zillions of page views), the trade-off is well worth it (and various types of caching can help reduce the performance hit).

查看更多
贪生不怕死
3楼-- · 2019-07-31 15:40

Jordan's answer is excellent, I would add that you probably don't see index.php in the url because you've enabled pretty URLs (type 'pretty' on concrete5's searchbox to check that).

Anyhow, the best way to programmatically add link to internal pages is:

<a href="<?=$this->url('page-name');?>"> 
    page name 
</a>

It works both on localhost and online, with or without pretty URLs.

(For the page-name go to dashboard/full sitemap/page-name/properties/page paths and location.)

查看更多
登录 后发表回答