Thread tagged as: Problem, Api, Runway

Using PerchSystem::set_page() with Silex


I am having difficulty in getting Perch to respond to inputs to PerchSystem::set_page when used within a Silex controller. I am currently building an API integration with a signup form with Perch layouts passed through to the Twig templates. The issue is that these are not picking up the changes made to the set page.

The two approaches I have tried have been to use before middleware and a regular expression to determine the URL string and to use the function directly within my controller methods. Looking at the debug information it is still referencing the index page rather than the path set. Using get_page() within the controller shows the correct path so I am wondering if it is some sort of scope or execution order problem.

Stripped out controller code:

protected $form_path = '/register/business';

public function matchBasicInfo(Request $request, Application $app)

I am using Perch Runway 2.8.26. The debug output mentioned is:

SELECT * FROM perch2_pages WHERE pagePath='/register/index.php' LIMIT 1
James Wigger

James Wigger 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That would work with Perch, but Runway has its own routing and expects to be the entry point for the request.

Thanks, Drew. As is typical I managed to figure it out just after posting! Silex's $app->run() executed after I was generating the Perch layout / regions so it was happening too late for Perch to use it. I've added a code block that sets the values before both of these fire and it has resolved the problem.

In case this helps anyone in future, the code is:

require __DIR__ . '/../../registration_app/app.php';

if(strpos($_SERVER['REQUEST_URI'], '/business') !== false) {

if(strpos($_SERVER['REQUEST_URI'], '/event') !== false) {

// Layouts
$app['twig']->addGlobal('PerchCMS', [ .... ]);