RE: [coldbox:5988] handler calling model

This comes up so much and the answer is on the ColdBox wiki and mention a
lot in these forums.

If you are getting this error and you have upgraded to ColdBox V3.0 M5/M6,
then you need to switch over to the new injects way of doing things.

So this

<cfproperty name="User" type="Model" scope="instance"/>

Now becomes

<cfproperty name="User" inject="model:user" />

Regards,
Andrew Scott
http://www.andyscott.id.au/

I am using CBM6 on cf 8.1

No need to create the instance Struct. Its done automagically.

West

here is what I have updated the code to and I am still getting the
same error

<cfcomponent name="User" extends="coldbox.system.EventHandler"
output="false" autowire="true">

<!------------------------------------------- CONSTRUCTOR
-------------------------------------------->

  <cfproperty name="UserModel" inject="Model:User" scope="instance"/>

  <cffunction name="init" output="false" returntype="User">
     <cfreturn this>
  </cffunction>

<!----------------------------------------- IMPLICIT EVENTS
------------------------------------------>

<!------------------------------------------- PUBLIC EVENTS
------------------------------------------>

  <cffunction name="ChkUser" access="public" returntype="any"
output="false">
    <cfargument name="Event" type="any">
    <cfscript>
      var rc = Event.getCollection();

      return instance.UserModel;
    </cfscript>
  </cffunction>

Hi, Chris:

I am *not* an expert on ColdBox, however, I think the problem is in your *inject* value.

1. I believe you should have the following in your /config/ModelMappings.cfm file:

  addModelMapping(alias="User", path="UserService or whatever it is named in your /Model directory");

2. Then, in your *inject* value, you would simply have "Model", the name should be your alias, like:

  <cfproperty name="User" inject="Model" scope="instance" />

Did I mention that I am NOT an expert? :wink:

Kevin S. Anderson
Superlative Solutions, Inc.

no dice, i tried changing it to : <cfproperty name="User"
inject="Model"/>

my model is named User.cfc as well, so I would think this should work

Try

<cfproperty name="User"
inject="model"/>

Curt

both this:

<!------------------------------------------- CONSTRUCTOR
-------------------------------------------->

  <cfproperty name="User"inject="model" scope="instance"/>

  <cfscript>
    instance=structNew();
  </cfscript>

  <cffunction name="init" output="false" returntype="User">
     <cfreturn this>
  </cffunction>

<!----------------------------------------- IMPLICIT EVENTS
------------------------------------------>

<!------------------------------------------- PUBLIC EVENTS
------------------------------------------>

  <cffunction name="ChkUser" access="public" returntype="any"
output="false">
    <cfargument name="Event" type="any">
    <cfscript>
      var rc = Event.getCollection();

      //var UserModel=getModel('model.User').init();
      //TestUser=UserModel.ChkUser();
      //sUsername=rc.username,sPassword=rc.password

      return instance.User;
    </cfscript>
  </cffunction>

or this:

<!------------------------------------------- CONSTRUCTOR
-------------------------------------------->

  <cfproperty name="User"inject="model"/>

  <cffunction name="init" output="false" returntype="User">
     <cfreturn this>
  </cffunction>

<!----------------------------------------- IMPLICIT EVENTS
------------------------------------------>

<!------------------------------------------- PUBLIC EVENTS
------------------------------------------>

  <cffunction name="ChkUser" access="public" returntype="any"
output="false">
    <cfargument name="Event" type="any">
    <cfscript>
      var rc = Event.getCollection();

      //var UserModel=getModel('model.User').init();
      //TestUser=UserModel.ChkUser();
      //sUsername=rc.username,sPassword=rc.password

      return User;
    </cfscript>
  </cffunction>

= the same problem

i think i may have found the problem, I was using this handy script to
dynamically add all of my models

<cfscript>
/**
* Deletes the n leftmost elements from the specified list.
* Modified by RCamden : objectivebias.com is coming soon

sorry for the multiple replies all, it appears it was the way that
script was setting up my model mappings that was screwing up
everything - now that I have removed the script and added my model
mappings manually the inject works like clockwork and I am refactoring
now

Is the name of your model User or UserModel? Depending on this you need that
with the model: declaration.

Also in CB 3.0 you don't need the autowire and extends anymore either, you
can still use them but they are not needed.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of chris hough
Sent: Friday, 1 October 2010 2:54 AM
To: ColdBox Platform
Subject: [coldbox:6007] Re: handler calling model

here is what I have updated the code to and I am still getting the same

error

Yeah you did, but what you say is not needed.

Regards,
Andrew Scott
http://www.andyscott.id.au/

I don't see how it is handy, everything in the model directory is already
able to be used without this code.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of chris hough
Sent: Friday, 1 October 2010 3:20 AM
To: ColdBox Platform
Subject: [coldbox:6013] Re: handler calling model

i think i may have found the problem, I was using this handy script to
dynamically add all of my models

<cfscript>
/**
* Deletes the n leftmost elements from the specified list.
* Modified by RCamden : objectivebias.com is coming soon
mappings-in-coldbox
*
* @param list The list to modify.
* @param numElements The number of elements to delete from the
left hand side.
* @param delimiter The delimiter to use. Defaults to a comma.
* @return Returns a string.
* @author Shaun Ambrose (shaun.ambrose@arcorsys.com)
* @version 1, April 24, 2002
*/
function ListDeleteLeft(list, numElements) {
  var i=0;
  var delimiter=",";

  if (Arraylen(arguments) gt 2) {
    delimiter=arguments[3];
  }

  if (numElements gt ListLen(list, delimiter)) return "";

  for (i=1; i lte numElements; i=i+1) {
    list=listDeleteAt(list, 1, delimiter);
  }
  return list;
}
</cfscript>
<!--- Add model mappings dynamically for all cfcs found in the /model
directory ---> <cfdirectory action="list"

directory="#expandPath('/model')#"

name="files" recurse="true" />
<cfloop query="files">
  <cfif right(files.name,4) is ".cfc">
    <!--- rip extension off component --->
    <cfset filename = left(files.name,len(files.name)-4)>
    <cfset thisPath = listAppend(listDeleteLeft
                    (files.directory,listFindNoCase

(files.directory,"model","/"),"/")

                                               ,filename,"/") />
    <cfset
addModelMapping(path=listChangeDelims(thisPath,".","/")) />
  </cfif>
</cfloop>

and it looks like this does not work right with CB 3.0 :frowning: - it was pretty

handy