Retrieving the just the form name class using namespaces

I have a code similar to this to handle a form submission:

use \my-project\web\models\forms\RegisterOrganizationForm;



$model=new LoginForm;



The output of that var_dump is (well, just the part regarding the values of the form):

["\my-project\web\models\forms\LoginForm"]=> array(1) {...

As you can see the namespace has been added, so, how can I get just something like this below when vardumping??:

["LoginForm"]=> array(1) {...


Have you tried something like:

use my\project\web\models\forms\LoginForm as Login;

$model = new Login();





Tahnks, but the result is the same…

You can’t without modifying Yii source code <_<

CHtml class uses get_class() function to render active forms and inputs.

get_class() returns the fully qualified name of a class, so its namespace is included in the returned string.

In order to use namespaced models, you must replace get_class() calls by something like getShortClassName() :

function getShortClassName($object) {

   $parts=explode('\\', get_class($object));

   return end($parts);


This must be done in CHtml::resolveName method but also in classes that generates client validation code (maybe in CValidator and children, I haven’t searched).

For my part, I prefer to wait for a new Yii release, and stay with models without namespace.

Where you able to find a solution to this? I’m running into the same issue and it’s a huge deal to have the full namespace like this in the form name…