Jump to content

Recommended Posts

Hi there.  I have a feeling this is a simple problem, but I can’t figure it out.

 

I'm using CodeIgniter and making use of the MVC concept.  One of the things that I do is create dynamic javascript in some of my views.  I know how to pass php variables to the view from my controller and use them to create the javascript I want on the page.

 

What I am trying to do is pass the variables to an external javascript file.  I like to keep all my javascript code in external files (and that seems to be widely encouraged).  I know how to use a dynamic external .js file using the .php extension, and I can run php code in the external javascript file just fine.

 

What I DON’T know how to do is to pass php variables from my controller that will somehow make their way into the external javascript files.  I realize I could call the external javascript files with a querystring that I could set dynamically, but what if I want to pass in an array, or a simplexml object or something.  I tried using global variables and didn’t seem to get anywhere with that.

 

Does anyone know how to do what I’m attempting?  Is it even possible?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.