Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

$application->handle(); triggers a "Wrong number of parameters" error after last upgrade

After the last upgrade to 4.0.0-alpha1 (Version 0.11.8-4495e75), my main application does not work anymore and returns a "Wrong number of parameters" error message.

It worked before the upgrade. I start my application just like in the Basic Tutorial:

//Create the main application 
$application = new \Phalcon\Mvc\Application($di);

try {
    // Handle the request

    $response = $application->handle(); //This guy stopped working
    $response->send();

} catch (\Exception $e) {
    echo $e->getMessage();
}

It looks like handle() now wants a parameter (the uri?) If I set one, it seems to work but then my website would only display a single url (the baseUri) regardless of which parameter I set in the handle() function.

Any idea ?



9.8k
Accepted
answer
edited Jan '19

You need to pass in the URI. For example you could use $_SERVER['REQUEST_URI'] or use the Phalcon request class

$request = new Phalcon\Http\Request();
$application->handle($request->getURI())

Probally you can get the Request from the DI



3.3k

Just tried with a new Request and it worked !

// Handle the request
$request = new Phalcon\Http\Request();
$response = $application->handle($request->getURI());
#$response = $application->handle(""); //This guy stopped working
$response->send();

Is the documentation going to be updated ?

You need to pass in the URI. For example you could use $_SERVER['REQUEST_URI'] or use the Phalcon request class

$request = new Phalcon\Http\Request();
$application->handle($request->getURI())

Probally you can get the Request from the DI



9.8k

Is the documentation going to be updated ?

Will be part of the final release for sure. Some info can already be found on the blog and you can track the status of the issues here

Greetings to you dear friends ! I have the code: in а file — index.php: try {

/**
 * Read the configuration
 */
$config = include __DIR__ . "/../app/config/config.php";

/**
 * Read auto-loader
 */
include __DIR__ . "/../app/config/loader.php";

/**
 * Read services
 */
include __DIR__ . "/../app/config/services.php";

/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

} catch (\Exception $e) { echo $e->getMessage(); }

and in file – services.php:

**

  • The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault();

/**

  • The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use ($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri);

    return $url; }, true);

When executing the code, an error occurs - "Wrong number of parameters". I can't figure out what's wrong... From the above example, I don't quite understand how to correct the query class. Please help the newcomer , it is very difficult for me...