Zend Framework error 3

Asked

Viewed 357 times

0

I’m trying to open the localhost:8080/person url but always has a fatal error ( Uncaught Zend Router Exception Runtimeexception) that I can’t interpret right.

My directories are like this:

-config
 *pplication.config.php
 *development.config.php
 *development,config.php.dist
 *modules.config.php
-data
-module
  -Application
  -Pessoa
    -config
      *module.config.php
    -src
      -Controller
        *PessoaController.php
    *Module.php
    -test
    -view
      -pessoa
        -pessoa
             *index.phtml   
-public
-vendor

Stack trace:

Fatal error: Uncaught Zend Router Exception Runtimeexception: Found unbalanced Brackets in C: Users Igor Desktop Projectozf2 vendor zendframework zend-router src Http Segment.php:218 Stack trace: #0

C: Users Igor Desktop Projectozf2 vendor zendframework zend-router src Http Segment.php(112): Zend Router Http Segment->parseRouteDefinition('/person[/:actio...')#1
C: Users Igor Desktop Projectozf2 vendor zendframework zend-router src Http Segment.php(147): Zend Router Http Segment->__Construct('/person[/:actio...', Array, Array) #2

C: Users Igor Desktop Projectozf2 vendor zendframework zend-router src Routeinvokablefactory.php(105): Zend Router Http Segment::Factory(Array) #3

C: Users Igor Desktop Projectozf2 vendor zendframework zend-servicemanager src Servicemanager.php(764): Zend Router Routeinvokablefactory->__invoke(Object(Zend Servicemanager Servicemanager), 'Zend Router Htt...', Array) #4

C: Users Igor Desktop Projectozf2 vendor zendframework zend-servicemanager src Servicemanager.php(227): Zend Servicemanager Serviceman in

C: Users Igor Desktop Projectozf2 vendor zendframework zend-servicemanager src Servicemanager.php on line 771

Files (I’ll put only the ones I edited):

modules.config.php

<?php
    return [
        'Zend\Router',
        'Zend\Validator',
        'Application',
        'Pessoa',
    ];

module.config.php

<?php 

namespace Pessoa; 
use Zend\ServiceManager\Factory\InvokableFactory; 


return [
    'router'  => [ 
        'routes' => [
            'pessoa' => [
                'type' =>\Zend\Router\Http\Segment::class,
                'options' => [
                    'route' => '/pessoa[/:action[/:id]',
                    'constraints' => [
                        'action' => '[a-ZA-Z][a-ZA-Z0-9_-]*', 
                        'id' => '[0-9]+', 

                    ],
                    'defaults' => [
                        'controller' => Controller\PessoaController::class, 
                        'action' => 'index',
                    ],
                ],
            ],
        ],
    ], 
    'controllers' => [
        'factories' => [
            Controller\PessoaController::class => InvokableFactory::class, 
        ],
    ],
    'view_manager' => [ 
        'template_path_stack' => [ 
            'pessoa' => __DIR__. '/../view', 
        ],
    ],
];

Personal controller.php

<?php

namespace Pessoa\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;


class PessoaController extends AbstractActionController 
{

    public function indexAction() 
    {
        return new ViewModel();
    }
}

Module.php

<?php

namespace Pessoa;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{ 

    public function getConfig() 
    {
        return include __DIR__."/../config/module.config.php";
    }
}

index.phtml

<?php
    $var = "Funciona!!!!!";
?>
<h1>Minha view do controller pessoa no modulo Pessoa</h1> 
<p><?= $var ?></p>
  • I don’t know the framework, but I seem to be missing one ] on the line 'route' => '/pessoa[/:action[/:id]', in module.config.php

  • Obg for help. I put the missing clasp. But still giving error, so another -> Compilation failed: range out of order in Character class at offset 26 in C: Users Igor Desktop Projectozf2 vendor zendframework zend-router src Http Segment.php on line 387

1 answer

-2

        'pessoa' => [
            'type' =>\Zend\Router\Http\Segment::class,
            'options' => [
                'route' => '/pessoa[/:action[/:id]]',
                'constraints' => [
                    'action' => '[a-ZA-Z][a-ZA-Z0-9_-]*', 
                    'id' => '[0-9]+', 

                ],
                'defaults' => [
                    'controller' => Controller\PessoaController::class, 
                    'action' => 'index',
                ],
            ],
        ],
  • 1

    Could you explain what that code is and why it would answer the question?

  • Simple, it’s just a matter of syntax, the code snippet of your code that I highlighted this with a syntax error.

  • You wrote: 'route' => '/person[/:action[/:id]', The correct is: 'route' => '/person[/:action[/:id]]',

  • Even if the code is not mine, it could be described in the answer, because in the current form it is not clear how you solved.

  • Excuse my ignorance, I’m new.

  • Matheus, just below your answer is the "Edit" option, use it to complete your reply with an explanation of what you did. As it is new on the site, I recommend you do the [tour] and go to [help] for more information.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.