Forum

Thread tagged as: Question, Runway

Dynamically Populate SLUG based on URL?

Hi I'm trying to dynamically pass a value for a slug to a page so that it matches the route and shows the correct content based on that slug.

My route on the page looks like this:

staff/[slug:urlslug]

I have defined $userurl as my slug in the page (user.php) and set as a variable:

// Fetch the user ID from the URL
  $url = trim($_SERVER[REQUEST_URI], '/');
  $url = substr($url, strrpos($url, '/')+1);
  $url = substr($url, strrpos($url, '-')+1);

  $userurl = ($memberProperty->username)."-".$url;

  PerchSystem::set_var('userurl', $userurl);

I then created and called a template (slug.html) for my field slug:

        perch_content_create('Username', array(
            'template' => 'slug.html',
        )); 

        perch_content_custom('Username', array(
            'template'=>'slug.html'
        ));

The field looks like this:

<perch:content id="urlslug" type="slug" />

When I then visit https://bell.dev/staff/david.cooper-76 I get a a page not found error.

The slug works when I link it to a title field - but that isn't what we want to do in this situation - it needs to be dynamically populated based on the URL. What am I doing wrong?

Debug

Time    Δ  Debug Message
0.0234  0   [38] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.0244  0.001   Using master page: /templates/pages/errors/404.php
0.0891  0.0647  [1] SELECT * FROM perch2_members_sessions WHERE sessionID='7a38be642ded98a19af6de5b9a44c18337f16699' AND sessionHttpFootprint='66718f4408095d586a7668f80adeb93087613fbf' AND sessionExpires>'2016-05-25 12:46:52' LIMIT 1
0.0894  0.0003  User is logged in
0.0919  0.0025  [1] SELECT * FROM perch2_pages WHERE pagePath='/errors/404' LIMIT 1
0.0929  0.001   [6] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/errors/404' OR regionPage='*' ORDER BY regionPage DESC
0.0932  0.0003  Request time: 0.0932
0.0932  0   Process time: 0.0918
0.0932  0   Memory: 5.6139

Diagnostic Report

Perch Runway: 2.8.25
Production mode: Development (10)
Installed apps: content (2.8.25), assets (2.8.25), categories (2.8.25), collection_1 (2.8.25), perch_events (1.9.2), perch_blog (4.6), perch_forms (1.8.3), perch_gallery_extended (2.8.6), collection_2 (2.8.25), perch_members (1.4.2)
DB driver: PDO
DB tables: perch2_backup_plans (0), perch2_backup_resources (0), perch2_backup_runs (0), perch2_blog_authors (1), perch2_blog_comments (0), perch2_blog_index (615), perch2_blog_posts (3), perch2_blog_posts_to_tags (0), perch2_blog_sections (1), perch2_blog_tags (0), perch2_categories (16), perch2_category_counts (2), perch2_category_sets (3), perch2_collection_index (530), perch2_collection_items (47), perch2_collection_revisions (13), perch2_collections (3), perch2_content_index (494), perch2_content_items (162), perch2_content_regions (9), perch2_events (3), perch2_events_categories (3), perch2_events_to_categories (3), perch2_forms (1), perch2_forms_responses (0), perch2_gallery_albums (1), perch2_gallery_albums_to_tags (3), perch2_gallery_image_versions (81), perch2_gallery_images (9), perch2_gallery_images_to_tags (48), perch2_gallery_smart_albums (2), perch2_gallery_tags (35), perch2_members (406), perch2_members_forms (0), perch2_members_member_tags (0), perch2_members_sessions (1), perch2_members_tags (0), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_routes (27), perch2_page_templates (41), perch2_pages (24), perch2_resource_log (76), perch2_resource_tags (26), perch2_resources (65), perch2_resources_to_tags (52), perch2_settings (46), perch2_user_passwords (0), perch2_user_privileges (48), perch2_user_role_privileges (79), perch2_user_roles (8), perch2_users (3)
Users: 3
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_blog',
        'perch_members',
        'perch_gallery_extended',
        'perch_forms',
        'perch_events',
    );
Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
Scheduled tasks for perch_events: update_category_counts (60 mins)
Editor plug-ins: markitup
H1: 6d14f7c74e6f904f24ddbdef72f95e0f
L1: 20d0668e70f29399daa6cb8340dfc5b2
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.7.6: done
on_sale_version: 2.8.29
update_2.7.8: done
perch_blog_update: 5.0
headerScheme: light
perch_blog_slug_format: %Y-%m-%d-{postTitle}
perch_blog_akismet_key:
perch_blog_max_spam_days: 0
dashboard: 1
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
perch_blog_comment_notify: 0
perch_gallery_update: 2.8.5
perch_gallery_bucket_mode: single
perch_gallery_bucket: default
perch_members_login_page: /members/login.php?r={returnURL}
perch_gallery_basicUpload: 0
update_2.7.10: done
logoPath: /login/resources/1425049619_CPI_Logo.png
update_2.8: done
update_runway_2.8.7: done
latest_version: 2.8.15
perch_blog_post_url: /feed/post/{postSlug}
update_runway_2.8.8: done
update_runway_2.8.9: done
perch_gallery_extended_update: 2.8.5
perch_gallery_extended_basicUpload: 0
perch_gallery_extended_bucket_mode: single
perch_gallery_extended_bucket: default
update_runway_2.8.11: done
update_runway_2.8.13: done
update_runway_2.8.17: done
perch_events_update: 1.8
perch_events_detail_url: /event/{eventSlug}
update_runway_2.8.25: done
perch_members_update: 1.4
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /Users/danlee/Sites/Work/bell
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: bell
PERCH_DB_PREFIX: perch2_
PERCH_TZ: Europe/London
PERCH_EMAIL_FROM: dan.lee@uk-cpi.com
PERCH_EMAIL_FROM_NAME: Dan Lee
PERCH_LOGINPATH: /login
PERCH_PATH: /Users/danlee/Sites/Work/bell/login
PERCH_CORE: /Users/danlee/Sites/Work/bell/login/core
PERCH_RESFILEPATH: /Users/danlee/Sites/Work/bell/login/resources
PERCH_RESPATH: /login/resources
PERCH_HTML5: 1
PERCH_PRODUCTION_MODE: 10
PERCH_YOUTUBE_API_KEY: AIzaSyDmHVMlNX7MHnm8PdE8Fl_k6DQZ_PBs0dM
PERCH_AD_ACCOUNT_SUFFIX: @uk-cpi.com
PERCH_AD_DOMAIN_CONTROLLERS: uk-cpi.com
PERCH_AD_BASE_DN: OU=sites,OU=CPI,dc=uk-cpi,dc=com
PERCH_AD_ADMIN_USERNAME: intranet.ldap
PERCH_AD_ADMIN_PASSWORD: nMBmY9HxujNY5Bqf
PERCH_DEBUG: 1
PERCH_RUNWAY: 1
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Users/danlee/Sites/Work/bell/login/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
HOSTING SETTINGS

PHP: 5.5.20
Zend: 2.5.0
OS: Darwin
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $
MySQL server: 5.6.24
Free disk space: 642.35 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, json, ldap, mbstring, session, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, mysql, shmop, SimpleXML, snmp, soap, sockets, exif, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, apache2handler
GD: Yes
ImageMagick: No
PHP max upload size: 120M
PHP max form post size: 122M
PHP memory limit: 228M
Total max uploadable file size: 120M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
HTTP_HOST: bell.dev
HTTP_CONNECTION: keep-alive
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
HTTP_REFERER: https://bell.dev/login/core/settings/diagnostics/
HTTP_ACCEPT_ENCODING: gzip, deflate, sdch
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
HTTP_COOKIE: p_m=7a38be642ded98a19af6de5b9a44c18337f16699; cmsa=1; _pk_id.1.27e1=fa12d6ab7e1b718b.1463478707.16.1464176805.1464173148.; _pk_ses.1.27e1=*; PHPSESSID=tncu5sg6vh93ck5q9062vs5gv1
PATH: /usr/bin:/bin:/usr/sbin:/sbin
SERVER_SOFTWARE: Apache/2.4.10 (Unix) PHP/5.5.20
SERVER_NAME: bell.dev
SERVER_ADDR: 127.0.0.1
SERVER_PORT: 80
REMOTE_ADDR: 127.0.0.1
DOCUMENT_ROOT: /Users/danlee/Sites/Work/bell
REQUEST_SCHEME: http
CONTEXT_DOCUMENT_ROOT: /Users/danlee/Sites/Work/bell
SERVER_ADMIN: you@example.com
SCRIPT_FILENAME: /Users/danlee/Sites/Work/bell/login/core/settings/diagnostics/index.php
REMOTE_PORT: 65055
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /login/core/settings/diagnostics/?extended
SCRIPT_NAME: /login/core/settings/diagnostics/index.php
PHP_SELF: /login/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1464176906.425
REQUEST_TIME: 1464176906
Dan Lee

Dan Lee 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think the slug token matches against dots. If you need a dot, then add a custom token, or use a more general predefined one like *.

Dan Lee

Dan Lee 1 points

Super! Changed to a hyphen and that did the trick.

Thanks Drew! :)