For php version 5.3. This line is working fine.
<?php echo CController::createUrl('/Reload/data')?>
But when I updated my php to 5.4. I am getting
Non-static method CController::createUrl() should not be called statically, assuming $this from incompatible context
What should I have to do to make it work in yii?
You need to access a controller object. Assuming you are working within a view you can use $this
to access the current controller object:
<?php $this->createUrl('/Reload/data')?>
Within a widget you can use $this->controller
:
<?php $this->controller->createUrl('/Reload/data')?>
If not, you can use Yii::app()->controller
:
<?php Yii::app()->controller->createUrl('/Reload/data')?>
I can't figure how this line would work even in PHP 5.3 since you are calling a non static method in a static context. CController::createUrl() actually references $this...
Anyway, back to your main point : in Yii1 you can also manage your URLs with CApplication::createUrl(), and the Application object is available anywhere in your code.