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.
Structure:
|- 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();
$debug->listen();
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);
$ld->registerNamespaces([
'Test\Models' => '../app/models/',
'Test\Libraries' => '../app/libraries/',
'Test\Controllers' => '../app/controllers/',
])->register();
$di->set('dispatcher', function() {
$dp = new Dispatcher();
$dp->setControllerSuffix('');
$dp->setActionSuffix('');
$dp->setDefaultNamespace('Test\Controllers');
return $dp;
}); #dispatcher
$di->set('view', function() {
$view = new View();
$view->setViewsDir('../app/views/');
$view->registerEngines([
'.volt' => function($view, $di) {
$volt = new Volt($view, $di);
$volt->setOptions([
'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
$rt->notFound([
'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 = 'https://test/';
$this->view->cdn = 'https://cdn.test/';
} #initialize
function error() {
exit('404');
} #error
} #class
// EFO: ./test/app/controllers/Base.php
<?php // Index.php
namespace Test\Controllers;
class Index extends Base {
function index() {
$this->view->pick('hello');
} #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">
<head>
<title>Test</title>
<meta charset="utf-8">
<link rel="stylesheet" href="{{cdn}}styles.css">
<script src="{{cdn}}scripts.js"></script>
</head>
<body>
<div id="wrap">
{% include 'menu.volt' %}
{% block content %}{% endblock %}
</div> <!--wrap-->
</body>
</html>
// 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!
[1] https://forum.phalcon.io/discussion/19169/phalcon-v40-doesnt-work