Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partialView() data function weird behaviour #540

Closed
Tyf0x opened this issue Aug 12, 2015 · 6 comments
Closed

partialView() data function weird behaviour #540

Tyf0x opened this issue Aug 12, 2015 · 6 comments
Labels

Comments

@Tyf0x
Copy link

Tyf0x commented Aug 12, 2015

I had to port old code from CF8 to CF11 and upgrade cfwheels from 1.0.X to 1.4.1 and obviously had to fix a few issues of compatibility, nothing special.

However a part of the code just stopped working and I narrowed it down to a includePartial() call.

This includePartial() automatically calls a data function that returns a struct containing a few text fields and a query result. But when the data was sent to the partial view, the query was missing: actually, some of it's fields were merged in the data structure.

Here is the partial view data function:

<cffunction name="partialView" returntype="struct" access="private">
    <cfset var data = {} />     
    <cfset var testqry = QueryNew("id, other")/>
    <cfset QueryAddRow(testqry)/>
    <cfset QuerySetCell(testqry, "id", 1)/>
    <cfset QuerySetCell(testqry, "other", "test1")/>
    <cfset QueryAddRow(testqry)/>
    <cfset QuerySetCell(testqry, "id", 2)/>
    <cfset QuerySetCell(testqry, "other", "test2")/>
    <cfset data.query = testqry />
    <cfset data.title = "Partial View Title" />
    <cfset data.desc = "blah blah blah" />
    <cfreturn data />
</cffunction>

and the partial view just dumps the "arguments" variable:

<cfoutput>
<h2 class="tit">#arguments.title#</h2> 
<p>#arguments.desc#</p>
<cfdump var="#arguments#"/><cfabort/>
</cfoutput>

Here is the result of the dump:

shot 2015-08-12

I would have expected to see the query, but instead find one of the rows merged into the structure.

If I modify the controller code as follow:

<cffunction name="partialView" returntype="struct" access="private">
    <cfset var data = {} />     
    <cfset var testqry = QueryNew("id, other")/>
    <cfset QueryAddRow(testqry)/>
    <cfset QuerySetCell(testqry, "id", 1)/>
    <cfset QuerySetCell(testqry, "other", "test1")/>
    <cfset QueryAddRow(testqry)/>
    <cfset QuerySetCell(testqry, "id", 2)/>
    <cfset QuerySetCell(testqry, "other", "test2")/>
    <!--- <cfset data.query = testqry /> --->
    <cfset data.otherRandomName = testqry />
    <cfset data.title = "Partial View Title" />
    <cfset data.desc = "blah blah blah" />
    <cfreturn data />
</cffunction>

I get:

shot 2015-08-12 1

Did I miss something or is it indeed a bug?

@perdjurner perdjurner added the bug label Aug 12, 2015
@perdjurner
Copy link
Contributor

Can you post your includePartial call as well please?

Thanks.

@Tyf0x
Copy link
Author

Tyf0x commented Aug 13, 2015

I unfortunately deleted the sample project made to demonstrate the issue, but my includePartial was simply called in the "view/controller/test.cfm" view:

[...]
<cfoutput>
<div class="container">
    <div class="left">
        #includePartial("partialview")#
    </div>
</div>
</cfoutput>
[...]

with a route like

<cfset addRoute(name="home", pattern="", controller="controller", action="test")>

@perdjurner perdjurner added this to the 1.4.2 milestone Aug 21, 2015
@perdjurner
Copy link
Contributor

Can you check if it has to do with naming the variable "query".

What if you name it "query2" instead for example, same problem?

@perdjurner perdjurner modified the milestones: 1.4.2, 1.4.3 Aug 31, 2015
@Tyf0x
Copy link
Author

Tyf0x commented Aug 31, 2015

Yes, I can confirm that the issue is only occurring when the variable is named "query". Changing the name to anything else (like "query2") works as intended.

@perdjurner perdjurner removed the waiting label Sep 5, 2015
@perdjurner
Copy link
Contributor

I don't think this is a bug but we do need to document it better.

The "query", "object" and "objects" arguments are special arguments and should not be used for other purposes than what's documented here:

http://docs.cfwheels.org/docs/partials

  • Using Partials with an Object
  • Using Partials with a Query
  • Using Partials with an Array of Objects

@perdjurner perdjurner removed this from the 1.4.3 milestone Sep 5, 2015
@perdjurner perdjurner added this to the 1.4.5 milestone Feb 26, 2016
@perdjurner perdjurner modified the milestone: 1.4.5 Mar 30, 2016
@perdjurner
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants