Collection 301 Redirects PHP errors

  • This great post form the old forum by Shane Lenzen shows how we can set up a Collection called 301 Redirects. In this Collection you can set page redirections!


    https://forum.grabaperch.com/f…p-301-redirect-collection


    However, I am finding that when the 404 is triggered I get a couple of PHP errors and I'd like to iron them out. Can anyone help?


    The errors are:


    Notice: Undefined offset: 0 in /Users/simonclay/Dropbox/Clients/Wycombe Homeless Connection/Wycombe Homeless Website/Site Folder/perch/core/runway/apps/content/PerchContent_Runway.class.php on line 426


    Warning: array_filter() expects parameter 1 to be array, string given in /Users/simonclay/Dropbox/Clients/Wycombe Homeless Connection/Wycombe Homeless Website/Site Folder/perch/templates/pages/errors/404.php on line 23


    The 404.php page code:


  • The first error is caused as perch can't find a template for the collection. Check if the collection key is correct and that it has a collectionTemplate set in the DB for the collection. If both are correct you can pass through the template as an option which should fix the notice.


    As it doesn't look like the template is found I imagine that the rest of the process of fetching the data isn't working. Are there any errors in the perch debug?

  • Again you are right Byron Fitzgerald !


    It seems a bit strange having to have template and skip-template in the custom query, but it works.


    Thank you.


    Code
    1. $result = perch_collection('301 Redirects', [
    2. 'filter'=>'old_url',
    3. 'match'=>'eq',
    4. 'value'=>$reqstring,
    5. 'count'=>1,
    6. 'template' => '301_redirects.html', //<-- added
    7. 'skip-template' => true,
    8. 'return-html' => true,
    9. ]);