2015-03-04 21:42
浏览 40

Yii:javascript的参数化调用 - 引号问题

I am using Yii Version 1.1.15.

In a View I use ajaxlink and it works like a charme:

        'onclick' => '$("#help").dialog("open"); return false;',
        'update' => '#help'), 
     array('id' => 'showHelp')
<div id="help"></div>

Since I have a lot of ajaxlink-calls, I want to write a function in the components-folder which I can call with: MyComponents::help("Help", "general/help", "help", "showHelp");

class MyComponents {
    public static function help($headline, $controller_and_action, $divname, $idname) {
                   'onclick' => '$("$divname").dialog("open"); return false;',
                   'update' => '$divname'), 
                 array('id' => '$idname')

Problem: If I call this in the browser, I only get an empty page.

Do I have to extend MyComponents with a parentclass? Which? (I don't think so: I tested echo CHtml::encode("test") without problems.

Maybe something wrong with my quotes?

I was googeling for hours and gave up. Hope it's not impossible.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douboshan1466 2015-03-04 23:29

    I solved the problem. It was very simple. I didn't get an erromessage and therefore thought that something was going wrong with javascript.

    In my controller I am not in an object-context - so $this->createUrl(...) is not possible. The solution:


    ... and it works like a charme ;-)

    打赏 评论

相关推荐 更多相似问题