Permalinks - Automatic Creation Problems
5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: August 9, 2013 (RSS)
By Perchpole - August 8, 2013 - edited: August 8, 2013
Hello, All -
I'm continuing my tests with Permalinks and another minor glitch has surfaced. Automatic Permalink creation doesn't appear to be working correctly.
Manual creation works fine. You simply provide the Custom source URL:
/indexCMS.php?p=3
...and your prefered Permalink:
contact-us
Job done. However, I don't want to give my content provides/clients access to the Permalinks DB as this is accessed via the Plugins section. The only alternative is to use the Automatic creation method.
I have followed the instructions which requires the creation of a text field in the editor called "permalink". The idea is that you enter your prefered Permalink here and then this will be used to create the link.
Instead of using a Custom source URL - like the manual method - the plugin captures the record table and number. In the case of the example above this would be pages and 3.
I'm not entirely sure how Permalinks works but my guess is that the automatic method tries to form a kind of query string from this data, perhaps like this:
[detail page URL]?[table]=[number]
which would give you:
/indexCMS.php?pages=3
However, as you can see in the query string from my example, instead of pages=3 I've employed the more simple p=3.
So, although the Permalink loads the correct page, much of the code on the page fails to load properly.
Is there a work-around?
:0/
Perch
By gregThomas - August 8, 2013
Hi Perch,
If you do a showme function on a request array on a detail page with a permalinks field in its section, you'll see that the num value for the record gets added to the request array automatically when it has a permalinks entry:
showme($_REQUEST);
and if my URL is:
http://example.com/test-record/?page=3&p=3
the showme on the request array outputs:
Array
(
[page] => 3
[p] => 3
[num] => 7
)
So the table name is not included in the URL, but you'll not be able to pass in a new num value, for example:
http://example.com/test-record/?page=3&p=3&num=133
still returns:
Array(
[page] => 3
[p] => 3
[num] => 7
)
If your using a getRecords function the correct record should be returned automatically if your using whereRecordNumberInUrl:
// load record from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
Are your page/p values being overwritten? Which version of the plugin are you using?
Thanks!
Greg
PHP Programmer - interactivetools.com
By Perchpole - August 8, 2013
Hi, Greg -
Thanks for your advice. The problem in my case is that I do not use whereRecordNumberInUrl in the getRecords call. I always found it unreliable/inflexible so started using a request variable:
$pageNum = @intval($_REQUEST['p']);
and then add this to the getRecords call:
'where' => " num = $pageNum "
Presumably this is why my the automatic Permalink isn't loading all of the page code properly.
:0/
Perch
By Perchpole - August 8, 2013
Greg -
I've made a few amendments to my code - which is now working better.
if(@$_REQUEST['p'])
{
$pageNum = @intval($_REQUEST['p']);
}
elseif(@$_REQUEST['num'])
{
$pageNum = @intval($_REQUEST['num']);
}
else
{
etc...
}
It's clunky but it seems to work. Is there a better way?
:o/
Perch
By gregThomas - August 9, 2013
Hi Perch,
I was going to suggest something very similar:
$pageNum = intval(coalesce(@$_REQUEST['p'],@$_REQUEST['num'],'2'));
So the above system works pretty much the same as the code in your previous post. The coalesce function will return the first value that is added to it that is either true or has a value. So if neither p or num exist in the request array 2 would be returned. If both p and num exsist in the request array, the value for p would be returned.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com