Yii Framework Forum: register a script file in assets - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

register a script file in assets Rate Topic: -----

#1 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 30 October 2008 - 01:36 PM

in a component extending CWidget I do

<?php
$foo=$this->controller->clientScript;
$foo->registerBodyScriptFile(dirname(__FILE__).'/fDimensions.js');
?>

and it includes the file at the bottom of the document. but the url of the src tag is the original one (under protected so it isn't unreachable by the web server).

what do I have to do to publish a js file in assets?

0

#2 User is offline   ilzale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 08

Posted 30 October 2008 - 01:50 PM

solved.

<?php
$clientScript=$this->controller->clientScript;
$clientScript->registerBodyScriptFile(Yii::app()->assetManager->publish(dirname(__FILE__).'/fDimensions.js'));
?>



0

#3 User is offline   lake 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 01-December 08

Posted 01 December 2008 - 07:56 PM

Quote

solved.


<?php
$clientScript=$this->controller->clientScript;
$clientScript->registerBodyScriptFile(Yii::app()->assetManager->publish(dirname(__FILE__).'/fDimensions.js'));
?>





Does this script file belong to 3rd part?
Eg:I want to use a calender.js ,how to make it run in a php file?
0

#4 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 01 December 2008 - 08:12 PM

You make an extension under protected/extensions and then for example:

<?php
$dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'colorpicker';
$baseUrl =Yii::app()->getAssetManager()->publish($dir);
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile($baseUrl.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'colorpicker.js');

in your init or run methods.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users