How To Get Only Model Name From A Model

hi i am trying to get model name or model class name of model as if User is model than I want its class as user,

I am using


$efolder=  get_class($model);

but gives me


app\models\User

but I only want User part, when I tried to explode it as due to backslash \ , explode function not working in class,

is there any method to get class name from model or other method to use explode in such condition.

Thank you

How do you plan to use the short class name?

If you plan to reuse it in your code like this below, you may need the complete namespaced classname anyway:




$class = get_class($model);

echo $class::CONST_VAR;



But if you are just looking at getting the short class name for other purposes, you can do something like this




$class = end(explode("\\", get_class($model))); // short class name



First does not work for me but second does. Thanks for the solution.

Ok good that it works.

Just to clarify if you understood what I said. The first method $class = get_class($model); was not to get the short class name, but the complete class name with namespaces. The next line echo $class::CONST_VAR; was an example on how you can access a constant inside the class.