0

Yep... (me...again!)

I am trying to troubleshoot some errors and when I go to dump allErrors() in my controller, it is simply an empty array, when I know for a fact it shouldn't be.

link.cfc (model)

<cffunction name="init">

<cfset validate(property='linkURL', method="validateUniqueUrl", when="onCreate") />

</cffunction>

<cffunction name="validateUniqueUrl" access="public">
        <cfif this.exists(where="linkURL='#this.linkURL#'")>
            <cfset this.addError(property="linkURL", name="linkExists", message="The link you entered already exists.") />
        </cfif>
    </cffunction>

If the link exists, I get the error correctly in my view:

<cfoutput>#errorMessagesFor("link")#</cfoutput>

However, in my controller, I want to dump all errors on the model by doing:

<cfdump var="#link.allErrors()#" abort />

Just a blank array! WTF?!

Even if I then try:

<cfdump var="#link.errorsOn("link")#" abort />

...again, an EMPTY array.

What in the world is going on here? Am I being an idiot or something?

Thanks. Michael.

UPDATE:

Ok, so it seems using <cfdump var="#link.allErrors()#" abort /> in my view works, but not in the controller? Why not? I need this in the controller so that I can then make a redirect!

Michael Giovanni Pumo
  • 14,338
  • 18
  • 91
  • 140

1 Answers1

2

Ok, I figured it out myself. Typical that this always happens minutes after I post the question. Lateral thinking??

I had to call the errorsOn() method AFTER the link.save() method.

I was declaring this into a variable BEFORE the link.save() method...so I guess CFWheels never knew at that point that there were errors...because obviously you have t attempt a save before knowing it errors right?

BHAM! Logic.

Michael Giovanni Pumo
  • 14,338
  • 18
  • 91
  • 140