0

Wrong number of parameters #0 C:\xampp1\htdocs\crud_by_phalcon\app\config\router.php(7): Phalcon\Mvc\Router->handle() #1 C:\xampp1\htdocs\crud_by_phalcon\public\index.php(20): include('C:\xampp1\htdoc...') #2 {main}

this is my code router

<?php

$router = $di->getRouter();

// Define your routes here

$router->handle(isset($_GET['_url']) ? $_GET['_url'] : '');

controller

<?php

use Phalcon\Mvc\Controller;

class ControllerBase extends Controller
{

}

my full code index.php

<?php
use Phalcon\Di\FactoryDefault;

error_reporting(E_ALL);

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

try {

    /**
     * The FactoryDefault Dependency Injector automatically registers
     * the services that provide a full stack framework.
     */
    $di = new FactoryDefault();

    /**
     * Handle routes
     */
    include APP_PATH . '/config/router.php';

    /**
     * Read services
     */
    include APP_PATH . '/config/services.php';

    /**
     * Get config service for use in inline setup below
     */
    $config = $di->getConfig();

    /**
     * Include Autoloader
     */
    include APP_PATH . '/config/loader.php';

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

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

    // $response = $application->handle();
    // $response->send();
} catch (\Exception $e) {
    echo $e->getMessage();
}
Tediace
  • 1
  • 2

2 Answers2

0

Check your phalcon version. In phalcon v3 your handle method hasn't any param, but from version 4 you must to include your URL:

public function handle( string $uri ): ResponseInterface | bool

So, you can write:

$router->handle(isset($_GET['_url']) ? $_GET['_url'] : '');
Chess
  • 36
  • 1
  • thank u for your feedback... I was trying to change my code that's working but right now I got some error on indeks.php "echo str_replace(["\n","\r","\t"], '', $application->handle()->getContent());" – Tediace Jul 18 '22 at 06:48
  • Try to do only echo $application->handle()->getContent(); to see if it works – Chess Jul 18 '22 at 08:07
  • I was updating my code in index.php but still got "Wrong number of parameters". can u pls review my code, sir? – Tediace Jul 18 '22 at 10:10
0

I use this in my index.php:

/**
 * Handle the request
 */
$application = new Phalcon\Mvc\Application($di);
$response = $application->handle($_SERVER["REQUEST_URI"]);
$response->send();

YMMV...