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

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

Closed
wants to merge 6 commits into from
Closed

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

wants to merge 6 commits into from

Conversation

Ciaro
Copy link
Contributor

@Ciaro Ciaro commented Mar 21, 2012

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

$response = Dispatcher::run(new Request(array(
'url' => '/users/login'
)));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, where do we go from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump -_-

@@ -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']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'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 Ciaro closed this May 18, 2012
@d1rk
Copy link
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.

@nateabele
Copy link
Member

@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants