Jump to content

Why multiple functions/methods that do the same thing?


Robin S
 Share

Recommended Posts

I remembered a blog post where Ryan introduced a new function wireRenderFile() for rendering a file and returning its output. But when I searched the new v3 API docs I couldn't find wireRenderFile() - instead I discovered $files->render() and WireFileTools::render() that seem to do the same thing as wireRenderFile().

And looking at the code it seems that wireRenderFile() is basically an alias for $files->render() which in turn is a shortcut to TemplateFile::render() see edit below

As a learner developer all of this got me wondering:

1. What is the benefit to making a new function like wireRenderFile() that seems to be just an alias for an existing method? I know there must be one because otherwise it wouldn't have been announced as something new in Ryan's post.

2. Is there a significant difference between WireFileTools::render() and $files->render()? The API docs say they are both shortcuts to using the TemplateFile class but unlike wireRenderFile() it looks like the code for WireFileTools::render() is not just an alias for another method but is actually independent. see edit below

Edit for posterity: I think I have it sorted out in my head now...

wireRenderFile() = $files->render() = WireFileTools::render(), and WireFileTools::render() makes use of TemplateFile::render() as part of the method.

  • Like 1
Link to comment
Share on other sites

16 hours ago, horst said:

access as a procedural function and not only as class instance

Thanks, I don't really understand the difference between these two. Do you mean there are situations where this works:

wireRenderFile('somefile.php', $my_vars, $my_options)

But this doesn't:

wire('files')->render('somefile.php', $my_vars, $my_options)

Or it's just a bit quicker/easier to do the first rather than the second?

 

Edit: Confusion resolved :). I just noticed that the wireRenderFile() function is different in PW 2.x versus PW 3.x. So it's only in 3.x that it's an alias for another method, so I can understand now why it was a new feature back when Ryan announced it in PW 2.5.2.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...