Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing a file with code ...

Status
Not open for further replies.

dbeezzz

Technical User
Nov 30, 2005
54
KR
I'm opening a file first, then parsing the contents with my_object function, and then I'd like to feed that output into another object.

Unfortunately though, the second object only accepts files instead of code on-the-fly as it were. Rather than start messing around with my template object, I'm wondering if there is another way I could feed in my code and have it accepted as a file.

I'll be running my code through my own class roughly something like this
Code:
$temp_code = $my_object -> output('index.tpl');

$template->set_filenames( 'index' => $temp_code  );

$template->assign_vars( 'VAR_1' => $row1 );

$template->assign_var_from_handle('INDEX' , 'index' );

$template->pparse('body');

The assign_var_from_handle expects a file, not code.
I'm basically wrapping the index.tpl in my own larger javascript/html file which is produced by my object.

 
This may not be the best answer, but you could write the code to a file and then send that file to the second object.

But I really do not think this a satisfactory solution. Did you write the second class, or are you using a pre-made class? I'm not sure what the second object does with the file, but I would consider adding a method to accept code.

Better yet, when I have an object which can accept incoming data in two different forms, I like to have a generic method named something like inputData(), then either dynamically figure out what form the data is in, or have the method accept a $data_form argument.

Depending on the form of the data, inputData() would call assign_var_from_handle() or assign_var_from_code(), where the data is formated from the source and sent back into the regular flow of the object.
 
Hi Itshim,

I'm using the opening and closing file technique at the moment, but that's just to check the functionality. I wouldn't feel right putting a file r/w into the code for every execution.

The second object is prepackaged, but so I'd prefer not to touch it if there was some magic way to convert data to a stream or something like that.

Anway, no biggie, I reckon I could probably overload the method without too much difficulty. <fingers crossed>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top