Yii class for direct file open (and about modifing JS script files)
Posted 28 October 2010 - 07:27 AM
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.
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.
Posted 28 October 2010 - 12:38 PM
Posted 28 October 2010 - 12:41 PM
1) have the main layout to write your global variables (in this case paths)
What do you think?
Posted 02 November 2010 - 03:14 AM
(...) have the main layout to write your global variables (in this case paths) (...)
What do you think?
Brilliant! Can't figure out why I didn't think about so obvious solution? :/
BTW: CFile extension looks very interesting.
This post has been edited by Trejder: 02 November 2010 - 03:46 AM
Posted 02 November 2010 - 10:41 AM
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.