I am using a plugin made by myself for dynamically show the menu. Sadly it throws an 500 error and the content of the website is empty, no code shown using view-source:site in chrome
But when I remove this piece of code from my ControllerBase.php:
public function initialize()
{
$this->content->setMenu((object) array("name" => "Home","url" => "/"));
$this->content->setMenu((object) array("name" => "Registreren","url" => "/register"));
$this->content->setMenu((object) array("name" => "Inloggen","url" => "/login"));
}
It will work again.
Help!
This is how my code looks like:
Url: /
IndexController.php:
<?php
use Phalcon\Mvc\View;
class IndexController extends ControllerBase
{
public function indexAction()
{
if($this->session->has("auth")){
$this->dispatcher->forward(array(
"controller" => "Game",
"action" => "index",
));
}
}
}
ControllerBase.php:
<?php
use Phalcon\Mvc\Controller;
class ControllerBase extends Controller
{
public function initialize(){
$this->content->setMenu((object) array("name" => "Home","url" => "/"));
$this->content->setMenu((object) array("name" => "Registreren","url" => "/register"));
$this->content->setMenu((object) array("name" => "Inloggen","url" => "/login"));
}
}
Services.php (content plugin code):
$di->set("content",function(){
return new content();
});
plugins/content.php:
<?php
class content extends Phalcon\Mvc\User\Component{
public function setMenu($menu)
{
global $menus;
if(!isset($menus)){
$menus = array();
}
$menus[] = $menu;
$that->view->setVar("menus",$menus);
}
public function emptyMenu(){
global $menus;
$menus = array();
}
}
view(for menus):
<nav>
{% if menus is defined %}
<ul>
{% for menu in menus %}
<li><a href="{{menu.url}}">{{menu.name}}</a></li>
{% endfor %}
</ul>
{% endif %}
</nav>