-1

i have just installed Apigility and following the tutorials i have an error. When i try with Postman to call my service i get an error like this

Zend\View\Renderer\PhpRenderer::render: Unable to render template "status/v1/rpc/ping/ping/ping"; resolver could not resolve to a file

My call on postman is like this. http://localhost/demo/api/public/ping

How to solve this problem?

  • Soooo... what's the issue? Obviously something's not rendering. But, what is the config? What is the route? Why are you using `public/` in the URL? Have you debugged your code, is your Controller executed? What is your response, a rendered view or should it be JSON (as you're using Apigility I'm assuming a JsonResponse), have you extended your Controller from the correct ZF provided Controller? Please read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) so we can properly help you out. – rkeet Mar 25 '19 at 11:15
  • I simply follow the Getting Started of Apigility. https://apigility.org/documentation/intro/getting-started. I don't do anything else. I run it under xampp , right create the Api and the Fields. Right have "error" response if i set wrong content on the request. – Massimiliano Oreto Mar 25 '19 at 11:38
  • So, if you go to your local address, do you see the admin panel? Have you used that to create your new "ping" ? Asking, because if you followed the example there, then you would have "Status" and not "ping" as the module name (though the service is ping). Have you created the Controller & Action? Please add all of this info in your question. Same goes for the Request and Response (use the Postman Console for the response). – rkeet Mar 25 '19 at 12:39
  • 1
    Yes, i see the panel and i create the element as the example. At the end, i find a part of solution. If i don't use ViewModel on the Return but simple return the result, it works. So is the ViewModel construct that make the error. Maybe the example is not so clear. I must create Control and Action to work with the example. I'm wrong thinking the example si fine :) . So the question is solved – Massimiliano Oreto Mar 25 '19 at 13:43

2 Answers2

1

For anyone have this problem, in the example of Apigility change the example code from this:

namespace Status\V1\Rpc\Ping;
use Zend\Mvc\Controller\AbstractActionController;
use ZF\ContentNegotiation\ViewModel;

class PingController extends AbstractActionController
{
public function pingAction()
{
    return new ViewModel([
        'ack' => time()
    ]);
}
}

to this

namespace Status\V1\Rpc\Ping;

use Zend\Mvc\Controller\AbstractActionController;

class PingController extends AbstractActionController
{
public function pingAction()
{

return ['ack' => time()];

}
}

Doing this the example is fine.

1

Apigility as part of Zend Framework is now part of the open source Laminas project and is called Laminas API Tools.

Make sure that Zend OPcache is disabled in your PHP configuration before trying to create your API service.

Quick steps to verify:

  1. create a phpconfig.php file that displays php configuration for your development server. Do not put this in production. See for details https://www.php.net/manual/en/function.phpinfo.php
  1. open this file on your server http://localhost:8080/phpconfig.php and look for two things a) ZendOPcache - if it is enabled, then look at b) loaded php.ini something like /etc/php7/cli/php.ini
  2. add opcache.enable=0 to the [opcache] section. Even if it is commented out, it is still loaded, you saw it above right?
  3. restart your PHP server / application to verify that Zend OPcache is off and that's it.