Hi there,
Does anyone knows about Yii class that would be a wrapper for basic PHP file open routines, like fopen? I know CFileHelper, but it hasn't got any function for opening a file directly stored on server.
Why would I need that, someone might ask? Well, I'm using: Yii::app()->clientScript->registerScriptFile() after Yii::app()->assetManager->publish() to include JavaScript file and be able to use it within a page.
But what about situation, when I have to actually change something inside JS file? For example: insert actual path to image files, it uses. If I would use it on static webpage, I would do one time edit of JS file and problem would be gone. But I'm using it in dynamic environment of Yii and I have no idea where file will be put by Yii after Yii::app()->assetManager->publish().
Well... I can publish files to assets folder from source but change permanently JS file by entering there paths pointing to source folder from where assetsManager publishes them. This might sound as some kind of idea. But what if files will be put on another server in another path/directory? Remember each time that I have to manually update paths in JS file?
I'm thinking about publishing all files that are needed via Yii::app()->assetManager->publish() except JS file I need to modify. Then open that file directly from source folder to a string, modify what I need (i.e. paths) and put to website with Yii::app()->clientScript->registerScript this time.
If anyone knows a better way to achieve it, I will apperciate any advise.
Page 1 of 1
Yii class for direct file open (and about modifing JS script files)
#1
Posted 28 October 2010 - 07:27 AM
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
#3
Posted 28 October 2010 - 12:41 PM
Also, about your problem... why don't you have inside that JS file the paths to be GLOBAL variables to the document. And then, you can:
1) have the main layout to write your global variables (in this case paths)
2) OR write a <script bla bla bla, that points to a controller action that actually renders /text-javascript mime-type, global variable contents, and this is the **first** script file in your website.
I think that is better than actually modifying javascript files.
What do you think?
best
1) have the main layout to write your global variables (in this case paths)
2) OR write a <script bla bla bla, that points to a controller action that actually renders /text-javascript mime-type, global variable contents, and this is the **first** script file in your website.
I think that is better than actually modifying javascript files.
What do you think?
best
#4
Posted 02 November 2010 - 03:14 AM
Antonio Ramirez, on 28 October 2010 - 12:41 PM, said:
(...) why don't you have inside that JS file the paths to be GLOBAL variables to the document. (...)
(...) have the main layout to write your global variables (in this case paths) (...)
I think that is better than actually modifying javascript files.
What do you think?
(...) have the main layout to write your global variables (in this case paths) (...)
I think that is better than actually modifying javascript files.
What do you think?
Brilliant!

BTW: CFile extension looks very interesting.
This post has been edited by Trejder: 02 November 2010 - 03:46 AM
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
#5
Posted 02 November 2010 - 10:41 AM
Happy to help... congrats...
When we can't find a solution to our problems we should do as the wise man does: back to basics.
We tend to assume and forget very obvious things in our overloaded head.
When we can't find a solution to our problems we should do as the wise man does: back to basics.
We tend to assume and forget very obvious things in our overloaded head.
Share this topic:
Page 1 of 1