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

Forward action between two modules on this same controllers name #28

Open
HarasimowiczKamil opened this issue Jan 24, 2013 · 7 comments

Comments

@HarasimowiczKamil
Copy link

When we have this same controller in two modules, example:

/application
|/constrollers
|  |--/Index.php
|/modules
|  |/Admin
|  |  |/controllers
|  |  |  |/Index.php

And in /modules/Admin/controllers/Index.php we do:

...
$this->forward('Index', 'index', 'index');
...

Then run indexAction in IndexController in Admin module but we want Index module.

My suggestion is to use namespace for controllers and models, with the name of the module. No namespace is the default module. Example

namespace Admin;

class IndexController
{
    public function indexAction()
    {
        $model = new \Admin\UserModel();
    }
}
@akDeveloper
Copy link

+1 for the namespace, although i dont know if this has any conflict with routes.

@laruence
Copy link
Owner

hmm, PHP implemented namespace in a very tricky way, that is, if you define a class Foo in a Namespace Bar, the really class name is 'Bar\Foo",

in the opinion of Yaf loader, it equal to class Bar_Foo, so if we supports namespace in module, how can the Yaf Loader tell controller A in module B (B_A) from the ctronller B_A?

@HarasimowiczKamil
Copy link
Author

I think in modules controller's name must be like Bar\Foo or Bar_Foo (if namespaces is off). Routes definitions can look this same, because we can get namespace from module name. Only problem is not backward-compatible, but in this form modules don't work correctly.

So to answer your question, Yaf loader know it is namespaces on or off (from php.ini), know what module it is from routes or default route like /module/controller/action so Loader can load good controller. But this is only a suggestion there may be a better solution.

@laruence
Copy link
Owner

hmm, php.ini is a way(bc), let me think about it. thanks

@akDeveloper
Copy link

There is an issue in the current implementation of modules. Controllers in a module can have the same name with controllers in another module. So Yaf loader can not load the right controller, in some cases (forwarding, extending).
Defining a module as a namespace then may partial solve the problem.

Assuming the controllers IndexController and Admin\indexController. IndexController can be found in default module (index) and Admin\IndexController can be found in Admin module.

But maybe there is also an Admin\IndexController in the default module (index). The right way should be
Index\IndexController in Index module, Admin\IndexController in Admin module and Index\Admin\indexController in Index module. So even default module (index) should have a namespace.
This can work without namespaces by replacing \ with _.

Right now, Yaf defines the current module from the Request right? That is why can handle controllers with the same name in different modules. But when there is a need to extend a controller between modules or forward a controller from a module to another, then appears the above problem.

@oc666
Copy link

oc666 commented Jul 11, 2013

Hey

Just encountered this issue.
Is there any decision about this issue?

Thanks, Ofer

@abxuz
Copy link

abxuz commented Dec 28, 2019

同感

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

No branches or pull requests

5 participants