MoroGasper / yii-usergroups

Automatically exported from code.google.com/p/yii-usergroups
0 stars 0 forks source link

Cannot redeclare class DefaultController #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
First of all, great module! Now I just need to set it up correctly or possibly 
there is a bug as detailed below:

What steps will reproduce the problem?
1. When I try to add a group or user through the 'root tools' tab
2.
3.

What is the expected output? What do you see instead?

I expect the user or group to be added

Instead I get this error:

Fatal error: Cannot redeclare class DefaultController in 
/patthtomysite/protected/modules/userGroups/controllers/DefaultController.php 
on line 21

What version of the product are you using? On what operating system?

Using 1.6.4

Operating system: Windows 7 Professional

Please provide any additional information below.

OK, first let me apologize for my ignorance in advance... I just started using 
YiiFrameWork about 3 days ago and your module today.  I am still learning all 
the in's and outs of components, models, controllers etc etc. 

Any newbie direction is appreciated! 

Thanks!

Original issue reported on code.google.com by westonr...@gmail.com on 20 Apr 2011 at 7:47

GoogleCodeExporter commented 9 years ago
Something similar happened to me and the cause was that i had imported the 
controllers of several modules in the main.php file and there was a conflict.
Check your imports.

Original comment by artur.ol...@gmail.com on 20 Apr 2011 at 8:42

GoogleCodeExporter commented 9 years ago
Thank you for your reply, I will take a look and see if that is the same issue 
I am having. 

So should we not import controllers from other module in the yii 
config/main.php file as a 'best practice'? 

When you say importing the controllers, you are not talking about importing 
components, correct?

See Below:

'import'=>array(
    'application.models.*',
    'application.components.*',
    'application.extensions.nestedset.*', // import nested set extension
),

'modules'=>array(
    'userGroups'=>array(
        'accessCode'=>'password',
        ),
    'cms'=>array(
        // this layout will be set by default if no layout set for page
        'defaultLayout'=>'cms',
        ),
        'support',
    'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>'password',
        'generatorPaths'=>array(
            'ext.gtc' // a path alias
        ),
        'ipFilters'=>array('myip1', 'myip2'),
        'newFileMode'=>0666,
        'newDirMode'=>0777,
    ),
),

Thank you again for any and all help you are able to provide.

~Rick

Original comment by westonr...@gmail.com on 20 Apr 2011 at 9:08

GoogleCodeExporter commented 9 years ago
it has a problem because the cms module has a class named default controller as 
well... did you find a way to solve it?

let me know otherwise i'll do some coding to avoid the problem.

Original comment by nic...@creationgears.com on 21 Apr 2011 at 10:29

GoogleCodeExporter commented 9 years ago
give me the exact steps to reproduce the error if you didn't find a way to 
solve it, so i can try to fix it... i also need to know what's into nestedset 
extension (i can't find it on yii website)

Original comment by nic...@creationgears.com on 21 Apr 2011 at 10:44

GoogleCodeExporter commented 9 years ago
I'm pretty new to the Yii Framework, it appears that all modules I have seen so 
far use the DefaulController to extend Controller.  I tried renaming all of my 
default classes which then corrected each issue for the redeclared class for 
each one.

I.E.

renamed my support module DefaultController to Support Controller, then the 
others as CmsController, UserGroupsController etc. It still was having 
redeclared class issues.

It seems that modules should have unique class names in the DefaultController 
files to make them compatible with other modules that have been created.  Maybe 
my issue is that I have links in my menu to both the crm module and a support 
module so the defaultcontroller files are being called by the script when the 
page loads and this is causing the redeclared class issues?

NOTE: I have now set all the classes back to 'DefaultController' for each 
module to get a baseline and I have loaded the default userGroups file for the 
module core to reset back to 'stock'... 

The nestedset extension includes CNestedSetBehavior.php and TreeBehavior.php I 
have attached my entire file structure(sanitized). I think they are part of the 
core functionality of the application skeleton. 

BTW, it is entirely possible that I have set something up incorrectly and I 
would not be opposed to doing a gotomeeting with you and have you take a look 
at my file structure etc directly. Let me know

Actually, I am attaching a 'sanitized' version of my file structure with pw and 
other security items 'hashed'. I am mainly just including files that I have 
edited and not the entire yii package.

Rick

Original comment by westonr...@gmail.com on 21 Apr 2011 at 7:13

Attachments:

GoogleCodeExporter commented 9 years ago
After looking closer to your problem and trying to include userGroups in a 
application i developed i stumbled into the same problem.

What steps will reproduce the problem?
1. Create a new yii application
2. Setup userGroups
3. Enable gii
4. Create a new test module
5. Goto Root Tools in userGroups

The problem is that userGroups needs to include every controller from every 
module to get the "public static $_permissionControl".
This is the way it fills the description tooltips for the permissions gridview.

Original comment by artur.ol...@gmail.com on 26 Apr 2011 at 1:56

GoogleCodeExporter commented 9 years ago
fixed.

changed name of usergroups default controller to avoid this kind of problems.

Original comment by nic...@creationgears.com on 26 Apr 2011 at 8:04

GoogleCodeExporter commented 9 years ago
That solved the problem as described but did not completely solved it because i 
had another conflict.
If you add the auditTrail module to the scenario i described then there the 
conflict appears with AdminController.
I wonder if there is another way to load the controllers without having 
conflicts.
Some kind of sandb
I tried using namespaces but had no success.
Another not so elegant way would be parse the Controller PHP file.

Original comment by artur.ol...@gmail.com on 26 Apr 2011 at 1:31

GoogleCodeExporter commented 9 years ago
... Some kind of sandbox include just the extract the tooltip contents variable 
...

Original comment by artur.ol...@gmail.com on 26 Apr 2011 at 1:32

GoogleCodeExporter commented 9 years ago
i've been thinking about that too... but i really think that we can come to a 
solution for something like that is really the use of namespaces...

parsing files is not really a solution... even if i rename all usergroups 
controllers there still might be some other conflict with two other modules 
using the same controller names.

Original comment by nic...@creationgears.com on 26 Apr 2011 at 2:27

GoogleCodeExporter commented 9 years ago
Well until you come up with a better solution i coded the parsing option.
Take a look to see what you think of it.
Look at the attached file.

Original comment by artur.ol...@gmail.com on 26 Apr 2011 at 8:55

Attachments:

GoogleCodeExporter commented 9 years ago
New version of with sUserGroupsAccess Model with some corrections

Original comment by artur.ol...@gmail.com on 26 Apr 2011 at 11:10

Attachments: