我想在我的yii项目中的APIController里面重复调用一个javascript函数。如何在yii控制器动作中使用Javascript/jQuery代码?
public function actionMytimer() {
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');
$hello = setInterval(test,1000);
function test(){
echo 'hellooo interval';
}
}
它非常有必要对我来说,在一个特定的时间运行“测试”的方法interval.Is这可能吗?如果没有,那么任何方式做到这一点?请help.Thanks在advnc。 这是当前的警告消息:
Fatal error: Call to undefined function setInterval() in /Library/WebServer/Documents/MediaPult/protected/controllers/APIController.php on line 449
你需要输出整个JavaScript代码。你不能在你的PHP控制器中运行它。尝试让它在纯HTML页面或jsfiddle.net中工作,然后从应用程序输出代码。 [这里有例子](http://stackoverflow.com/questions/12796021/how-to-use-jquery-with-the-yii-framework) –
如果你想在控制器中运行一些方法,你需要使用[Yii控制台命令](http://www.yiiframework.com/doc/api/1.1/CConsoleCommand) –
@TorinFinnemann:谢谢man.It工作:)) – Ajit