Permalinks

5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 4, 2013   (RSS)

Hello,

I have created a section editor called "web_pages" and the detail page is "page.php".

I have created several records for different web pages I would like to display. For example an "About us" page, a "Contact us" page and a "Services" page.

I realise I can create individual PHP files for each record/web page and just set them to have a limit of 1 and then state where num=X

    'limit'       => '1',
    'where'       => 'num=1',


However, I was wondering if it's possible to create URLs using the single file "page.php". So I could have the following URLS:

about.php is in fact page.php?num=1
contact.php is in fact page.php?num=2
services.php is in fact page.php?num=3


Is it possible to achieve this with cmsBuilder? With Wordpress this is the Permalinks function...

Any help would be much appreciated.

Thank you,
Greg

Hi Greg,

This is possible, and should be fairly straight forward to do. You can use a getRecord function to get the record number from the URL and get the appropriate record.

  // load record from 'blog'
  list($web_pages, $blogMetaData) = getRecords(array(
    'tableName'   => 'web_pages',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $page= @$web_pages[0]; // get first record
  if (!$page) { dieWith404("Record not found!"); } // show error message if no record found

Let me know if you have any other questions on setting up this system. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg,

Thanks for your response. I have inserted the code you provided into "page.php".

Can you give me an example of how I set up a link please?

I would like to display the content of the "About" record, which can be accessed at "/page.php?num=1" with the URL "/about.php".

I am not clear on how to change the filename from "page.php?num=1" to "about.php"? Do I need to use .htaccess to achieve this?

Thanks,

Greg

Hi Greg,

Mnay thanks for your help. I am now up and running.

Regards,

Greg