Permalinks

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

By gversion - February 3, 2013

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

By gregThomas - February 4, 2013

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

By gregThomas - February 4, 2013

Hi Greg,

You could create a list of links to the individual pages like this:

// load records from 'web_pages'
list($links, $linkMetaData) = getRecords(array(
'tableName' => 'web_pages',
'loadUploads' => true,
'allowSearch' => true,
));

?>


<?php foreach($links as $link): ?>
  <a href="page.php?<?php echo urlencode($link['title']).'-'.$link['num']; ?>" ><?php echo $link['title']; ?></a><br/>
<?php endforeach;


?>

You would need to create the individual htaccess rules if you want to change the name of the page that appears in the URL. If you look at my post on this thread:

http://www.interactivetools.com/forum/forum-posts.php?Writing-friendly-URLs-with-.htaccess-INFORMATION-ONLY-78451

I've added a link to a site that will generate the rules for you. Although you could also try using the system suggested by zaba.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gversion - February 4, 2013

Hi Greg,

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

Regards,

Greg