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

Fatal error: Cannot instantiate abstract class ExampleUserIdentity #46

Closed
pavlyuts opened this issue Feb 17, 2014 · 12 comments
Closed

Fatal error: Cannot instantiate abstract class ExampleUserIdentity #46

pavlyuts opened this issue Feb 17, 2014 · 12 comments

Comments

@pavlyuts
Copy link
Contributor

I try to implement the module and use ExampleUserIdentity directly. This lead to runtime error on 'register' action
Fatal error: Cannot instantiate abstract class ExampleUserIdentity in ......\protected\modules\usr\models\RecoveryForm.php on line 58

PHP error table shown after the form fields.
usr-error

When I try to explicitly import classes via Yii config 'import' block as 'usr.components.', 'usr.models.' i got error: "Alias "usr.components.*" is invalid. Make sure it points to an existing directory or file. "

Any Ideas?

@nineinchnick
Copy link
Owner

You can't use the example identity provided with the module directly. That's why it has the Example prefix in the name and is abstract. You could create a UserIdentity class that extends it, but really the best way is to copy that class to your components directory and just rename it.

Where do you import usr components and models?

@pavlyuts
Copy link
Contributor Author

I was tryed copy and rename, but result exactly the same with different class name, regardless of what name of file and class I chose.

I was tryed to import with code like
$config['import'][] = 'usr.components.';
$config['import'][] = 'usr.models.
';
In main Yii confg file. $config is Yii config array. That leads to exception "file not found"

Extra, If I use class name 'UserIdentity' I have extra error from NetBeans parser in UserIdentity.php line 30, "Impossible to create abstract class instance \UserIdentity", but no runtime error there. Possible that have some relations to the fact that "UserIdentity" already defined within Gii extension.

I have checked with debug dump, $userIdentityClass in ProfileForm.php has correct value. Sime issues with php version/enveronment? Any ideas?

@nineinchnick
Copy link
Owner

Yii import runs before modules are registered and doesn't know module aliases. If you want to use it there you have to first define the usr alias yourself.

If you copy the code, remove the abstract keyword. Abstract classes cannot be instantiated and have to be extended.

@pavlyuts
Copy link
Contributor Author

%$#^$$#! I miss that simple thing, sorry a lot!

@nineinchnick
Copy link
Owner

No problem, I'm happy to help and see that anybody actually uses my module. As you can see from browsing the issues, there is almost no user feedback.

@pavlyuts
Copy link
Contributor Author

Thanks! But I told you that I have to code now after about 15 years of other job? So, I am really stupid as a developer ))))))

I fix that problem, but now nothing happens when "register" form is submitted )))

I guess that I need to ancest/copy all classes named starts with "Example" to get user management in my Yii instance up and running? Which way is the best? To move it to corresponding Yii folders? Rename and edit on place? Both approaches leads to future problems with your module update.

Think, it's much better if you have "turnkey" module if you wish you module widely deployed.

@nineinchnick
Copy link
Owner

The best way is to copy all (three) models and user identity to your app and rename them removing the "Example" prefix and "abstract" keyword if present.
Then copy the migrations, again adjust their names to current dates and apply.

Those examples implement all available interfaces that allows using all module features. You probably don't need most of them, so you could strip those example classes after copying them. For example, there's a separate model and table name for used passwords and extra columns for one time passwords.

Because the module relies on interfaces it doesn't require a specific implementation of them. Provided identity class doesn't even have to implement all interface, only selected ones. Even if I update the example implementations those changes are not required for the whole module to work.

The main reason for me to make the module was to be able to plug it into existing projects without modifying the user table. All other modules used hardcoded column names, like lastvisit_at. My module asks the user identity class you provide for that data, so if some columns are named differently your user identity class can map that when returning response to the module.

@pavlyuts
Copy link
Contributor Author

Thanks for explanations. Some of topics I guess, some of them new and usefull, so let's have some code :)))

@nineinchnick
Copy link
Owner

I must say I haven't had much occasions to use interfaces in my career so I understand. Also, I'd like to improve the docs (readme) to make this more clear. It would be great to use your current experiences as a newcomer to at least figure out the order in which the instructions should be written.

If you'd be willing to give it some time you can edit a single file directly on Github.

@pavlyuts
Copy link
Contributor Author

Think I am not representative! I'am just have to make some prototype to check how it works and then on success convert the project to the normal mode where each man do right job. I was strong in OOP almost two decades ago, and it's helps, but not enough.
I think any project should have two coplimentary docsets:

  1. Fasttrack "how to get it up and running" - for prototypers, reviewers and men who comparing differens solutions by trying each one. The core idea is to supply "copypaste" set allowing to make system alive enough to supply core operations.
  2. In deph docset. It's clear that the source is the ultimate docs, however comments in the source is not the best way just because you newer may be shure where to go for the information. Therefore the separate intermediate level is usefull, I think it should contain at least:
    a) object tree - described
    b) directory tree - described

I think at your separate case "Fasttrack" should looks like:

  1. Unpack to the "modues"
  2. Adjust Yii config file. (full-option-config-file-here-comment-out-what-you-don't-need-fill-options-which-demanded)
  3. Copy Exmple* to ..., remove "example" from filenames, "example" and "abstract" from class defs
  4. Enjoy!

Guess, it's useless for hardcore profi, but valued for newbies like me ;)

@pavlyuts
Copy link
Contributor Author

I have done 3 steps like described above and it works ;) Fine!

Could you be so kind to explain:

  1. it is possible to make social login part open new window on social button press and close it after login instead of operate in same window?
  2. Is it possible to list social bindings in profile?
  3. Is it normal operation to show Register+login for after succesfull social authorisation?

Thanks in advance!

@nineinchnick
Copy link
Owner

  1. You could override module views by enabling a theme, but I'm not sure the controller actions can be used that way. Please create a separate issue for that, I'll see if that can be improved.
  2. I've got a separate issue Remote identities managment #39 for that.
  3. It can get a little complex:
    • if you're logged in locally and log in remotely, the local and remote identities are associated automatically - this is currently missing in user profile
    • if you're not logged in locally, when you log in using a remote identity we could fetch an email and try to associate a local acount; in theory, you could steal somebody else local account, that's why you either have to log in to associate an existing local account or create a new one; maybe the registration form should be pre-filled or hidden and the login could also be simplified by filling the username

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

2 participants