PHP-PhantomJS:Twig_Error_Runtime?

时间:2017-03-03 23:01:32

标签: php-phantomjs

我正在学习php-phantomjs并且正在学习Twig_Error_Runtime。这是我的PHP:

    $location = '/Applications/myWebApp/js/phantomjsTest.proc';
    $serviceContainer = ServiceContainer::getInstance();

    $procedureLoader = $serviceContainer->get('procedure_loader_factory')
            ->createProcedureLoader($location);
    $client->getProcedureLoader()->addLoader($procedureLoader);

    $request = $client->getMessageFactory()->createRequest();
    $request->setType('phantomjsTest');

    $response = $client->getMessageFactory()->createResponse();
    $client->send($request, $response);

    if ($response->getStatus() === 200) {
        // Dump the requested page content
        echo $response->getContent();
    }

...这是我的.proc文件:

phantom.onError = function (msg, trace) {
    console.log(JSON.stringify({
      "status": msg
    }));
    phantom.exit(1);
};

var system = require('system');
var uri = "http://www.jonnyw.me";

var page = require('webpage').create();
page.open(uri, function (status) {
    console.log(JSON.stringify({
      "status": status
    }));

    if (status === "success") {
        page.render('example.png');
    }
    phantom.exit(1);
});

phantom.exit(1);

我错过了什么?提前感谢所有信息。

1 个答案:

答案 0 :(得分:0)

我通过替换它来实现它:

$request->setType('phantomjsTest');

......用这个:

$client->setProcedure('phantomjsTest');