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.

Full App In Phalcon v4.0 Not Working!

I got micro app working as per this post [1] but full app that worked fine in phalcon v3 doesn't work anymore in v4. How can I use this same "Request" if it required by v4 to get this app going? Software Used: PHP v7.3.0, Phalcon v4.0.0-alpha1. This is the stracture and code I have now.


|- test/
|--> app/
|-----> app/cache/ (volt cache files)
|-----> app/config/
|---------> app/config/bootstrap.php
|---------> app/config/routes.php
|-----> app/controllers/
|---------> app/controllers/Base.php
|---------> app/controllers/Index.php
|-----> app/views/
|---------> app/views/main.volt
|---------> app/views/menu.volt
|---------> app/views/hello.volt
|--> public/index.php
<?php // index.php

$debug = new \Phalcon\Debug();

require '../app/config/bootstrap.php';
echo $app->handle()->getContent();

// EOF: ./test/public/index.php
<?php // bootstrap.php

use Phalcon\Loader;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Application;

$ld = new Loader();
$di = new FactoryDefault();
$app = new Application($di);

    'Test\Models' => '../app/models/',
    'Test\Libraries' => '../app/libraries/',
    'Test\Controllers' => '../app/controllers/',

$di->set('dispatcher', function() {
    $dp = new Dispatcher();
    return $dp;
}); #dispatcher

$di->set('view', function() {
    $view = new View();
        '.volt' => function($view, $di) {
            $volt = new Volt($view, $di);
                'compiledPath' => '../app/cache/',
                'compiledExtension' => '.html',
                'compiledSeparator' => '_',
                'stat' => true,
                'compileAlways' => true,
            ]); #options
            return $volt;
        } #volt
    ]); #engines
    return $view;
}); #view

$di->set('router', function() {
    $rt = new Router(false);
    require '../app/config/routes.php';
    return $rt;
}); #router

// EOF: ./test/app/config/boostrap.php
<?php //routes.php

    'controller' => 'base',
    'action' => 'error'

$rt->add('/', [
    'controller' => 'index',
    'action' => 'index'

// EOF: ./test/app/config/routes.php
<?php // Base.php

namespace Test\Controllers;

class Base extends Controller {

  function initialize() {

    $this->view->web = 'http://test/';
    $this->view->cdn = 'http://cdn.test/';

  } #initialize

  function error() {
  } #error

} #class

// EFO: ./test/app/controllers/Base.php
<?php // Index.php

namespace Test\Controllers;

class Index extends Base {

    function index() {


    } #index

} #class

// EOF: ./test/app/controllers/Index.php

// menu.volt

<a href="{{web}}home">Home</a>
<a href="{{web}}about">About</a>

// main.volt

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <link rel="stylesheet" href="{{cdn}}styles.css">
    <script src="{{cdn}}scripts.js"></script>
<div id="wrap">
{% include 'menu.volt' %}
{% block content %}{% endblock %}
</div> <!--wrap-->

// hello.volt

{% extends 'main.volt' %}
{% block content %}

<h1> Hello, Phalcon v4.0 </h1>

{% endblock %}

I get this following error:

BadMethodCallException: Wrong number of parameters
// ERROR LINE: echo $app->handle()->getContent();

Any help is appreciated. Thank You!


edited 11d ago

Just found this on [1] blog post. But how do I use this with above code example? Anyone!? There is no examples given O_O

The Phalcon\Mvc\Application, Phalcon\Mvc\Micro and Phalcon\Mvc\Router now must have a URI to process



In index.php

echo $app->handle($_SERVER['REQUEST_URI'])->getContent();


$request = new Phalcon\Http\Request();
echo $app->handle($request->getURI())->getContent();


Thank you buddy, it works now. But why this change in v4 ?


Not sure, probally because an application can also have other inputs then uri. For example a cmd-line application.


It paves the way for simulating an entire request. Wow its really a lot of work but you could have a mock request, response and session service and then check that the output is correct.