We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Phalcon ZEPHIR mysterious error when call isPost

Hello i got this error:

PHP Fatal error:  Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' in /var/www/fairplayauto.cz/web/app/modules/WebModule/controller/RadceController.php:214\nStack trace:\n#0 [internal function]: Phalcon\\Http\\Response->setJsonContent()\n#1 /var/www/fairplayauto.cz/web/app/modules/WebModule/controller/RadceController.php(214): Phalcon\\Http\\Request->isPost()\n#2 [internal function]: Web\\Controller\\RadceController->ekonomikaAction()\n#3 [internal function]: Phalcon\\Dispatcher->dispatch()\n#4 /var/www/fairplayauto.cz/web/app/bootstrap.php(257): Phalcon\\Mvc\\Application->handle()\n#5 /var/www/fairplayauto.cz/web/public/index.php(56): require_once('/var/www/fairpl...')\n#6 {main}\n  thrown in /var/www/fairplayauto.cz/web/app/modules/WebModule/controller/RadceController.php on line 214, referer: https://fairplayauto.cz/radce/jizda/

On line where is the isPost:

if($this->request->isPost()){ // <-- here is the line
            $data['desc'] = $this->request->getPost();
                $car->car->fn_data = base64_encode(serialize($data));
                    $d = unserialize(base64_decode($car->car->fn_data));
                else {
                    $this->flash->error('Omlouváme se něco se nepovedlo, opakujte akci prosím později.');

And i can't understant why it happens, because it happen just sometimes, this has happen when i had upgrade phalcon to zephir.

edited May '15

I've been trying to figure out your problem, but I have no direct solution. It seems like the error is to do with the response rather than the request and the method it complains about:


is defined like this:

     * Sets HTTP response body. The parameter is automatically converted to JSON
     *  $response->setJsonContent(array("status" => "OK"));
     * @param mixed content
     * @param int jsonOptions
     * @return Phalcon\Http\ResponseInterface
    public function setJsonContent(var content, jsonOptions = 0) -> <ResponseInterface>
        let this->_content = json_encode(content, jsonOptions);
        return this;

I could not see that it is called elsewhere (but it must be) so my guess is that either the getPost() triggers a call to setJsonContent() via some filter/validator or something you have added or it happens when the redirect returns.

Another thing is that inside the if-statement you're unserializeng into $d which is apparently never used - don't know if this is somehow related or not.