We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Reflection - Model

Hi,

got a little problem. I want to optimize my code and not to repeat it for some functionality.

I want to use PHP's reflection-abilities with a model.

In a model I wanna call another model, so I do the following: ... $record = new Names(); $record->title = $author; ...

Now I change it to: ... $class = 'Names'; $record = new $class(); $record->title = $author; ...

Now error occures: Class 'Names' not found.

Using PHP 5.4, Phalcon 1.3.

What's the way getting it working? Cannot figure it :/

Thanks alot and very much for your time.

Greetz Aljoscha



98.9k

Do you have a class called Names? Are you using namespaces?

Sorry, not enough information from me:

Yes, I've got a Model called Names. It's working fine, when I don't call it by variable -- as in the first example above.

Yes, I use namespaces.

I call the Model Names in a method of Model Entities, which is in the same namespace, but it starts with "use SlipBOX\Models\Names, ...".

The problem occurs only if I use a variable instead of calling Names directly.

Thanks for your help!