1

I'm new to CFWheels and frameworks in general.

I'm following the screencasts on the Wheels website: http://cfwheels.org/screencasts/

I was following the tutorial exactly as is...the only difference is, where his table is named "people", mine is named "users". I made the changes accordingly, but kept everything else the same.

His singular is "person" and mine is "user".

Here's the insert code in my "User.cfc" controller:

<cfcomponent extends="Controller" output="true">

    <cffunction name="register">

        <cfset user = model("user").new() />

    </cffunction>

    <cffunction name="create">

        <cfset params.user['userUUID'] = createUUID() />
        <cfset params.user['userCreated'] = createODBCDateTime(now()) />
        <cfset params.user['userModified'] = createODBCDateTime(now()) />

        <cfset user = model("user").new(params.user) />
        <cfset user.save() />

    </cffunction>

</cfcomponent>

Now, I'm also using the form helpers etc in my view like so:

<cfparam name="user" />

<cfoutput>

#startFormTag( action="create" )#

<fieldset>

    <legend>Register</legend>

    #textField( label="User Name http://#cgi.server_name#/user/", objectName="user", property="userName" )#
    #textField( label="Email Address", objectName="user", property="userEmail" )#
    #textField( label="Password", objectName="user", property="userPassword" )#
    #submitTag( value="Register" )#

</fieldset>

#endFormTag()#

</cfoutput>

Pretty simple right? So I can't understand why it isn't inserting. Does it have something to do with naming my CFC "user" and also having a table called "users" with my singular name set as "user"?

When I submit the form there are no errors. It executes just fine but then if I look in the DB, there's nothing.

One thing I thought...is...exactly HOW does wheels even know what Table to look for? There doesn't seem to be any explanation for this. Perhaps it just locates the wrong table?

Many thanks, Michael


SOLVED!

Hi everyone, just an update for anyone else who might come across this. The reason nothing was happening was because my database table REQUIRED certain fields not to be null. CFWheels wasn't throwing any errors. Once I passed values to these fields it was fine; so just be sure to check that one out!

Hope that helps.

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

2 Answers2

2

Michael, first I might suggest you rename your controller to Users.cfc (plural).

In Wheels (and Rails and other similar convention over configuration frameworks), models are singular (User.cfc) while controllers and tables are plural (Users.cfc). Your code all looks solid and the only thing that jumped out at me was that your controller was noted as being "User.cfc".

One thing I might do in my create/update controller methods is something like this:

if (user.save()){
    flashInsert(success="The user was created successfully.");
    redirectTo(action="index");
} else {
    flashInsert(error="There was an error creating the user.");
    renderPage(action="new");
}

user.save() will return a boolean value and this conditional allows you to do some actual error handling/investigations if something were to go wrong and the save failed.

In terms of the question on how Wheels knows what table to look for, Wheels does this by convention. [paraphrasing how it works here] It checks your models and, for each model, it will check to see if a pluralized version exists in your DB. So, if there is a model called "User" then Wheels will expect there to be a table called "Users".

craig.kaminsky
  • 5,588
  • 28
  • 31
  • This approach is spot on. Wheels does not "throw" errors when there are validation failures, but rather it records the errors within the object instance. It's up to you then to report the errors to the user using this approach. – Chris Peters Jul 17 '12 at 18:51
1

Michael,

My first step in troubleshooting model object functions is normally to dump a the results allErrors() method. Try adding this line right after you attempt the save.

<cfdump var=user.allErrors() label="User Save Errors" abort />

MC