Yii Framework Forum: Yii class for direct file open - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii class for direct file open (and about modifing JS script files) Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 28 October 2010 - 07:27 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 28 October 2010 - 12:38 PM

Here you go man, get this extension for your purposes:

CFile
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#3 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

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
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#4 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 02 November 2010 - 03:14 AM

View PostAntonio 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?

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

Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#5 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

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.
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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