Fixing double use of library key in Router::match(). #388

Closed
wants to merge 6 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

Ciaro commented Mar 21, 2012

Failing test included + fix for issue #374 and #321.

@gwoo gwoo commented on the diff Mar 22, 2012

tests/cases/net/http/RouterTest.php
@@ -754,6 +755,19 @@ public function testSuffixContinuation() {
));
$this->assertEqual('/versions/13', $result);
}
+
+ public function testSubmoduleRoutes() {
+ Router::connect('/users', array('controller' => 'submodule.Users'));
+ Router::connect('/users/{:action}', array('controller' => 'submodule.Users'));
+
+ $response = Dispatcher::run(new Request(array(
+ 'url' => '/users/login'
+ )));
+
@gwoo

gwoo Mar 22, 2012

Owner

this looks like an integration test now. are you sure the correct library/controller will be dispatched?

@Ciaro

Ciaro Mar 22, 2012

Contributor

Yeah, I was in doubt whether it was an integration test or not. Never the less, it should proof the bug...

@gwoo

gwoo Mar 22, 2012

Owner

It may show "a" bug, but not 'the" bug. Also, fixing this bug may introduce other bugs because the integration test is incomplete. We need to make sure that the proper library is loaded when the key is unset.

@Ciaro

Ciaro Mar 22, 2012

Contributor

So, where do we go from here?

@Ciaro

Ciaro Apr 12, 2012

Contributor

bump -_-

@nateabele nateabele commented on the diff Apr 30, 2012

net/http/Router.php
@@ -215,6 +215,10 @@ public static function match($url = array(), $context = null, array $options = a
$suffix = isset($url['#']) ? "#{$url['#']}" : null;
unset($url['#']);
+ if (is_array($url) && isset($url['library'])) {
+ unset($url['library']);
@nateabele

nateabele Apr 30, 2012

Owner

This doesn't look like the correct fix at all. How would this not break all attempts to route to a library?

@Ciaro

Ciaro Apr 30, 2012

Contributor

@nateabele Have a look at the library logic in Dispatcher::applyRules

@Ciaro

Ciaro Apr 30, 2012

Contributor

'Dispatcher::applyRules' makes sure both the library key and the controller library prefix (lib.controller) are set, since some users use the library key, others the prefix. I also think this 'magic' is needed to make the route self-aware of it's context (it's part of the library x). Without that key lithium will think the route is part of the main app, and try to render the templates and layout found in app/views/* (instead of for example app/libraries/li3_docs/views/*). I've been using this fix for a month now, unsetting $url['library'] in the router hasn't shown any issues for me so far. I hope this makes things a bit more clear from my perspective...

Ciaro Vermeire added some commits May 1, 2012

Ciaro Vermeire Fixing double cookies bug. be2d28a
Ciaro Vermeire Minor Qa. d57dc4e
Ciaro Vermeire Merge remote-tracking branch 'upstream/master'
Conflicts:
	tests/cases/net/http/RouterTest.php
c9da319
Ciaro Vermeire Fixing failing apc test on Zend Server platforms. 42d631b

Ciaro closed this May 18, 2012

Member

d1rk commented Jul 25, 2012

I recently came over this issue and had a lot of struggle with views within libraries. Probably, this is not the correct solution, but it would then help to have some guidance on how to do things properly.

If possible, we can go into a chat on irc to further clarify what this is all about. Thanks for more information about that topic.

My current solution looks like that:

# libraries/radium/config/routes.php
Router::connect('/configurations/{:action}/{:args}', array('controller' => 'radium.Configurations'));
Router::connect('/configurations', array('controller' => 'radium.Configurations'));

# libraries/radium/controllers/BaseController.php
    public function _init() {
    parent::_init();
    $this->_render['paths'] =  array(
        'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
        'layout'   => LITHIUM_APP_PATH . '/views/layouts/{:layout}.{:type}.php',
        'element'  => LITHIUM_APP_PATH . '/views/elements/{:template}.{:type}.php',
    );
}

It does not work as expected, but it gets me closest to what i want to achieve. That is: rendering the view from the plugin, but the layout from the app. Elements are the big question here, still working on that.

Owner

nateabele commented Sep 15, 2012

@d1rk Views within libraries is a separate, but we're addressing it over here: #639.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment