rosse
June 30, 2017, 7:08am
1
Hi there!
I have a route that looks like this:
$app->get('/admin/home/', function ($request, $response, $args) {
$uc = $this->get('user_controller');
$view = $uc->view($request, $response, $args);
$this->view->render($view['response'], 'home.phtml.twig', $view['args']);
})->setName('home')->add('verify_request');
And a controller that looks like this:
public function view(Request $request, Response $response, $callable)
{
$shop = $request->getParam('shop');
$clientid = ClientModel::where('shop', $shop)->pluck('id');
$args[] = UserModel::where('client_id', $clientid)->select('first', 'last', 'email', 'trade', 'confirmed')->get();
return ['response' => $response, 'args' => $args];
}
But Slim errors with: Argument 1 passed to Twig_Template::display() must be of the type array, null given
and PHP errors with: array_merge() /Users/me/multiphp/vendor/twig/twig/lib/Twig/Environment.php(373) : eval()'d code:32
It feels like I’ve definitely don’t something wrong, but the lack of high level ‘usage fault’ style error message has made me think that I may have found a wierd edge case?
If anyone has any suggestions, I’d love to hear them as I’m slamming my head against this so hard right now xD
Thanks,
Ross
First thing first:
the view signature is (Request $request, Response $response, $callable)
you are sending (Request $request, Response $response, array $args)
The problem may be that $args
is not set anywhere in the view method.
1 Like
rosse
August 16, 2017, 8:22am
3
Hi there.
Thanks for that, but I don’t think that’s my issue, as that signature works in other places in my code base.
For some context, here’s my stack trace (the relevant bits at least)
Details
Type: TypeError
Message: Argument 1 passed to Twig_Template::display() must be of the type array, null given, called in /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Environment.php(373) : eval()'d code on line 53
File: /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Template.php
Line: 364
Trace
#0 /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Environment.php(373) : eval()'d code(53): Twig_Template->display(NULL)
#1 /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Template.php(389): __TwigTemplate_f9e517470031f9ce57c36a23bb16c04dd4f046045e8b44ef9677422fd30c2fbe->doDisplay(Array, Array)
#2 /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Template.php(366): Twig_Template->displayWithErrorHandling(Array, Array)
#3 /Users/user1/Dropbox/some_folder/multiphp/vendor/twig/twig/lib/Twig/Template.php(374): Twig_Template->display(Array)
#4 /Users/user1/Dropbox/some_folder/multiphp/vendor/slim/twig-view/src/Twig.php(88): Twig_Template->render(Array)
#5 /Users/user1/Dropbox/some_folder/multiphp/vendor/slim/twig-view/src/Twig.php(116): Slim\Views\Twig->fetch('home.phtml.twig', Array)
Not sure if that’s any more help.
Appreciate any help or suggestions at all at this stage, it’s a real doozy.
A part of my code.
I never use render directly, but get the rendered result to pass back.
(Gives you an opportunity to debug the rendered content)
public function index()
{
$oRepository = new ProductRepository($this->container);
$dataRecords = $oRepository->getList();
$result = $this->view->fetch($this->templateDir . '/index.twig',
[
'dataRecords' => $dataRecords
]
);
$this->response->getBody()->write($result);
return $this->response;
}