Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:14+00:00 2026-05-28T07:30:14+00:00

I am using YII framework for my web application . I have a question

  • 0

I am using YII framework for my web application . I have a question on registering external Java script file.

Could some one please help me ?

  1. What is the best location to copy Java script file ( which folder )
  2. I do see there are two ways to register that external Java script
    file

    First approach

     $baseUrl = Yii::app()->baseUrl; 
     $cs = Yii::app()->getClientScript();
     $cs->registerScriptFile($baseUrl.'/js/yourscript.js'); 
    

    Second approch

     $cs=Yii::app()->getClientScript();
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish('path/to/js'));
     $cs->registerScript('id', 'your js here');
    

In the first approach I am directly registering with registerScriptFile and passing the java script file

In the second approach I am registering and publishing the script . That means it copies to assets folders. ( Please correct me If I am wrong )
and then what does the last step does, What is id and again java script file . ($cs->registerScript('id', 'your js here');)

In my case I am accessing it from one of the views , so in the second approach since it gets published to the asset folder , if 10 clients calls the file does it published 10 times ( since I am accessing it from the view file )

I am bit confused .

Thanks for your answer

Regards

Kiran

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:30:15+00:00Added an answer on May 28, 2026 at 7:30 am

    Yii Assets folder is generally used by Widgets and Yii’s internal components like Gridview. You don’t need to store or publish your external JS or CSS files to assets folder.

    Secondly if the files already exist in assets folder getAssetManager()->publish('path/to/js') will not copy it againg.

    and last you don’t need to instantiate CClientScript class, you can call it directly as

    Yii::app()->clientScript->registerScriptFile(
        Yii::app()->baseUrl.'/js/file.js'
    );
    

    or if you are using themes

    Yii::app()->clientScript->registerScriptFile(
        Yii::app()->theme->baseUrl.'/js/file.js'
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using Yii framework and I have a -newbie- question about the
I'm using Yii to construct a web application. One of my input forms has
I am developing web application using Yii framework. currently i am in the process
I am building a web application with PHP/MySQL using the Yii framework. Key aspect
I developed an application with different MVCs using the Yii Framework For example I
I am implementing role based access control using yii framework for the application mentioned
I'm using Yii framework. On a couple of pages I want to add some
I'm working with Yii framework and using smarty view render. I have to working
I am using PHP Yii Framework with MongoDB(yiimongodbsuite). I have created a Model which
I am using YII framework at one of my project and I am facing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.