Can the names for directory and model be different

Hi,

All my table names have a prefix and some of them have suffixes too, e.g. co_country_m. Can I make DevTools generate all views in directory excluding the prefix and suffix, i.e. country.

Thanks, Amal

I'm afraid devtools has no such feature.

A hacky but fast solution would be to create a script that operates on the already generated classes, removes the pre+suffix from file and classname, and overrides with the corresponding table name in getSource().

Or, you can create your own models generator. I could share our repo, but it's streamlined for our project and may be useless to you :]



2.2k
edited May '17

I don't understand. Can you explain more with an example ?

This link might be help you :

https://blog.phalconphp.com/post/tutorial-creating-a-custom-models-initializer

If you found something, can you post here your solution ?

His problem is, that having a table name like co_country_m will generate model classes like CoCountryM.

Obviously that's cumbersome to use in PHP, so he's looking for a method to generate classes like Country, where the getSource can be set to co_country_m.

At least that's my understanding



7.2k
edited May '17

Thanks for your prompt replies. Yes, you are perfectly right @lajosbencz, what you wrote is what I wanted to achieve. I was trying to see if I can edit the DevTools Scaffold.php temporarily and get it to generate all the code but I get some errors - it can't find the model file. I want that the views also should use Country in all their links. I should probably do some post processing as you suggested. Will the Phalcon router create any issues for me if I use country everywhere - can't visualize.



2.2k
edited May '17

If you have some tables using same prefix and suffixes, perhaps you can use Country to generate with Devtools and create a template model to extend or something like that :

class CoModel extends Phalcon\Mvc\Model
{
    public function getSource()
    {
        return 'co_' . strtolower(get_class($this));
    }
}

https://stackoverflow.com/questions/16940788/table-prefix-configuration-in-phalcon-model