How to: POS_END to all js in ClientScript

Ok, i’m so sorry for my bad, bad, bad english.

I need that all .js zii files are placed at the end with CClientScript :: POS_END. But I need to do it in the configuration file. I see that I can do ‘*. Js’ => ‘all.js’, but I have not figured out how to assign the position. A help?

Thanks! :)

I don’t know if I completely understand what you are trying to do but if you want to change the default behavior for CCLientScript - and in your case I assume registerScript - you would have to modify this:




public function registerScript($id,$script,$position=self::POS_READY)

{

    $this->hasScripts=true;

    $this->scripts[$position][$id]=$script;

    if($position===self::POS_READY || $position===self::POS_LOAD)

        $this->registerCoreScript('jquery');

    $params=func_get_args();

    $this->recordCachingAction('clientScript','registerScript',$params);

    return $this;

}

to




public function registerScript($id,$script,$position=self::POS_END)

{

    $this->hasScripts=true;

    $this->scripts[$position][$id]=$script;

    if($position===self::POS_READY || $position===self::POS_LOAD)

        $this->registerCoreScript('jquery');

    $params=func_get_args();

    $this->recordCachingAction('clientScript','registerScript',$params);

    return $this;

}

Or whenever you call registerScript simply pass POS_END.

http://www.yiiframework.com/doc/api/1.1/CClientScript#registerScript-detail


public CClientScript registerScript(string $id, string $script, integer $position=4)

Hello, thanks for reply.

I’ve tried to create in components folder the class MyClientScript, then i’ve extended CClientScript and i’ve overwrited:





class MyClientScript extends CClientScript {

    

    public function registerScriptFile($url,$position=parent::POS_END) {

        parent::registerScriptFile($url, $position);

    }

    

    public function registerScript($id, $script, $position = parent::POS_END) {

        parent::registerScript($id, $script, $position);

    }



But scripts like jquery.cookie remain on <head> section.

Obviously the debug toolbar tells me that the class MyClientScript is loaded correctly.

EDIT

[b]

[/b]

Ok, i found the solution. Simply i’ve overwrited:




public $coreScriptPosition=self::POS_END;



You should not override within the code, it is a public variable thus can be configured at your main.php config file.

I modified the configuration file with your suggestion and I deleted the custom class. Thank you :)