This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I am building a real estate plugin. Currently, it has a controller for each type of Lead i.e. house, apartment, villas, etc. All these controllers more or less have the same exact code except their configs and other stuff. So I made a GenericController.php and made all the Controllers inherit that. I added code to it
    public $implement = [
        'Backend.Behaviors.FormController',
        'Backend.Behaviors.ListController'
    ];
    public $formConfig = 'config_form.yaml';
    public $listConfig = 'config_list.yaml’;as even that is common to both.
For settings the Backend menu correctly I wrote this
        BackendMenu::setContext('Mohsin.Leads', 'leads', $this -> get_class_name(get_class($this)));
   /* Given the namespaced classname, this returns the classname after converting it to lower case */
    public function get_class_name($classname)
    {
        if ($pos = strrpos($classname, '\\')) return strtolower(substr($classname, $pos + 1));
        return $pos;
    }Now I’m wondering if I can get rid of House.php, Apartment.php, Villa.php and just use an array like $types = [‘House’, ‘Apartment’, ‘Villa’]; and then call some function to register the controller? Is this possible. If so how?
1-1 of 1