Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No action or controller set for view in v1.2.4 #1275

Closed
skintagain opened this issue Sep 23, 2013 · 7 comments
Closed

No action or controller set for view in v1.2.4 #1275

skintagain opened this issue Sep 23, 2013 · 7 comments

Comments

@skintagain
Copy link

Using latest source (1.2.4) routes created with Annotations do not configure the action or controller options within the view. Have not confirmed if it relates to multi-module setup, but to reproduce:

$router->addModuleResource(...);

In controller:

/**
 * 
 * @RoutePrefix("/hello")
 */
class HelloController extends ControllerBase
{
    /**
     * 
     * @Get("/foo")
     */
    public function testAction() {
        echo $this->view->getActionName();
        echo $this->view->getControllerName();
    }
}

The route has been matched but both variables are not populated with the action or controller names. Replicated and works fine in 1.2.3.

@phalcon
Copy link
Collaborator

phalcon commented Sep 23, 2013

This is not a bug, $this->view->getActionName() and $this->view->getControllerName() aren't populated there, these methods only return data if the View is currently rendering a view. You can use echo $this->dispatcher->getActionName() and echo $this->dispatcher->getControllerName()

@skintagain
Copy link
Author

Unfortunately in 1.2.4 is doesn't even render the appropriate view though. I have had to rollback to 1.2.3 to get it to work. Am I missing something?

@phalcon
Copy link
Collaborator

phalcon commented Sep 23, 2013

That could be a bug, can you please submit a test to reproduce the problem?, Currently we have the forum and the main website running with 1.2.4 and the views are properly rendered. Also that version is passing all the tests on Travis: https://travis-ci.org/phalcon/cphalcon/builds/11691271

@skintagain
Copy link
Author

It looks like it could be a combination of multi-module and Annotations that cause it. When I get change I will replicate with a test

@skintagain
Copy link
Author

OK - still haven't had chance to work on a test but this is a definite bug and can re-produce quickly:

Using multi-module so I have done addModuleResource on the router

Using the following code:

/**
 * 
 * @RoutePrefix("/hello")
 */
class HelloController extends ControllerBase
{
/**
     * 
     * @Get("/test")
     */
    public function testAction() {
        echo $this->dispatcher->getControllerName();
     }        

Results:

v1.2.3 show 'hello'
v1.2.4 show '\Hello' so it fails to render the view

However if I change the @RoutePrefix on the controller to '/Hello' on 1.2.4 it shows the correct Controller name

@ghost
Copy link

ghost commented Oct 19, 2013

Test case:

<?php
/**
 * @RoutePrefix("/hello")
 */
class HelloController extends \Phalcon\Mvc\Controller
{
    /**
     * @Get("/test")
     */
    public function testAction()
    {
        echo $this->dispatcher->getControllerName(), PHP_EOL;
    }
}

$di = new \Phalcon\DI\FactoryDefault();
$di->setShared('view', function() { return new \Phalcon\Mvc\View(); });
$di->setShared('router',
    function()
    {
        $router = new \Phalcon\Mvc\Router\Annotations(false);
        $router->setUriSource(Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
        $router->addResource('Hello');
        return $router;
    }
);

$application = new \Phalcon\Mvc\Application($di);

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/hello/test';
echo $application->handle()->getContent();
?>

@skintagain
Copy link
Author

Huge thanks for fixing this. We need a phalcon-con so I can buy you a beer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant