Auto import doesn't work for me

Hey there,

I’m trying to get Auto-import to work but still have no luck. I’ve searched a lot on the internet and cannot find any solutions. I see examples all over the internet which look exactly the same as what I did.

I have configured the following in the config file:


'import'=>array(

	'application.models.*',

	'application.components.*',

	'application.helpers.*',

),

Then I have a ‘protected/helpers/Html.php’ file which contains the following:


<?php

class Html extends CHtml

{

    public static function rootUrl($url = '') {

        return Yii::app()->theme->getBaseUrl() . $url;

    }

}

It just gives a fatal error when executing the rootUrl() function in a view file…

Can someone please tell me what I’m doing wrong? Probably a n00b question in this case, but that’s exactly what I am when it comes to Yii.

Thanks in advance,

Instinct

Would help if you have written the error you get, and how you call this function…

If you get - fatal error: Call to undefined function rootUrl()

means you called the function as rootUrl(’…’) instead of Html::rootUrl(’…’);

Yeah well it’s a static function so I can also call it by using simply rootUrl()

Anyway, I used the following code to use the function:


<script type="text/javascript" src="<?php echo rootUrl('/js/main.js'); ?>"></script>

And I get the following error:


Fatal error: Call to undefined function rootUrl() in blabla

I tried to use exit(‘test’); on the top of the Html.php class file so it must exit with the printed word ‘test’, just for debugging. But just it doesn’t exit…

Someone can tell me? Could it be cached or something like that?

But have you at least tryed to use Html::rootUrl() ?

rootUrl() is not a static function… it’s a static method of the class Html… that’s why you call it as Html::rootUrl()

Ahhh you’re right I see. It now works. But yesterday when I put a exit(‘asd’); in it on the top, then it didn’t work. Now, today, it just works :S Little bit confused right now but happy that it works :D

Thanks