possible bug in redirectTo()

58 views
Skip to first unread message

dhga...@gmail.com

unread,
Feb 14, 2021, 8:47:25 PM2/14/21
to CFWheels
I have narrowed down a possible bug in the redirectTo() function using

CFML Engine
: Adobe ColdFusion2016,0,16,320445

CFWheels Version
: 2.2.0

I have tried different arguments, and each time, I get the same ERROR:
  // ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES.


// in  ./controllers/Users.cfc

component extends="app.controllers.Controller" {    
// ...
    function update() {
                  
        user=model("user").findByKey(params.key);
        if(user.update(params.user)) {
           
// ALL of the following functions FAIL with ERROR:
redirectTo(route="users"); // GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 

            //redirectTo(route="Users"); // GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 

            //redirectTo(controller="users", action="show", method="get", key=params.key);  // GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 

            //redirectTo(controller="users", action="show", key=params.key); // GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 

           
            //redirectTo(route="users", key=params.key, success="user successfully updated"); // GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 

            //redirectTo(action="show", key=params.key);
// GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES. 


            //redirectTo(route="users", key=params.key, success="user successfully updated");
// GIVES: ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES.
            
            //redirectTo(route="user");     // As expected Gives ERROR: Wheels.IncorrectRoutingArguments
           


// HOWEVER the following does NOT give an error:
            renderView(controller="users", action="show", method="get", key=params.key); // NO ERROR

        } else {
    
            flashInsert(error="ERROR: User #params.key# was NOT updated !!");
            renderView(action="edit");
        }
    }

// All other functions in controller are ok.

// my ./config/routes.cfm is as follows;

    mapper()
    
        .get(name="processendofyear", to="home##processendofyear")
       
        .get(name = "scanupc", to="upcs##scanupc")
           
            .resources("posts")
            .resources("comments")
            .resources("users")
            .resources("profiles")
            .resources("employees")
            .resources("authors")
            .resources("bios")
            .resources("customers")
            .resources("subscriptions")
            .resources("publications")


        .resources(name="upcs")
       
        .resources(name="inventoryitems")
        .resources(name="inventoryevents")
       
        .resources("receipts")
        .resources("pfstmts")       
        .resources("zselectaptabbrs")
        .resources("zselectwarehouselocations")  
        .resources("zselectpaymentmethods") 
        .resources("zselectstorenames")
        .resources("zselecttaxcats")
        .resources("zselectinveventtypes") 
        .resources("zselectinveventstates") 
        .resources("zselectdhgpfsnames")
        .resources("zselectdhgpfstypeofvalues") 

        .get(name="sayHello", to="ttt_say##hello")

// CLI-Appends-Here

        .wildcard()
        .root(to="home##index", method="get")
    .end();


// Let me know if I should add to to ;  https://github.com/cfwheels/cfwheels/issues/



Adam Chapman

unread,
Feb 15, 2021, 4:17:34 PM2/15/21
to CFWheels
Have you tried reloading the application with ?reload=true

Is there a route named "users" when you visit the "routes" tab?

dhga...@gmail.com

unread,
Feb 21, 2021, 7:41:53 AM2/21/21
to CFWheels
Yes I have tried ?reload=true .  ERROR occurs when the last .findByKey() DOES NOT find a record in the database ... as in;

variables[local.ms]= variables.model(local.ms).findByKey(key=params.key, include=local.nestedProperties);
if(!isObject(variables[local.ms])){
     flashInsert(error="ERROR~240: #local.ms# #params.key# was not found !");
      params.flash_error= flash();
      flashKeep();
      redirectTo(route=local.mp, error=local.ms & ' ' & "#params.key# was not found !");
     }


STILL HAVING ERROR !

dhga...@gmail.com

unread,
Mar 8, 2021, 3:32:50 PM3/8/21
to CFWheels
SOLVED / BUG?: This was a weird problem. Just upgraded to CFW 2.02.  The problem was that I added;

<cfscript>// FILENAME: /events/onabort.cfm
// Place code here that should be executed on the "onAbort" event.
renderView(template = "onerror.cfm" );
</cfscript>

and also;

<!--- FILENAME: /events/onerror.cfm --->
<!--- Place HTML here that should be displayed when an error is encountered while running in "production" mode. --->
<h1>Error!</h1>
<p>
    Sorry, that caused an unexpected error.<br>
        Please try again later.
</p>


BUG: renderView(template = "onerror.cfm" ); is giving the "ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES."

SOLUTION is to add  variables.params.controller= "home";   to onabort.cfm -- Not sure why renderView() works this way

<cfscript>// FILENAME: /events/onabort.cfm
// Place code here that should be executed on the "onAbort" event.
variables.params.controller= "home"; /* HACK to avoid "ERROR:  Element PARAMS.CONTROLLER is undefined in VARIABLES."  */
renderView(controller="home", action="onerror"  , layout=false, cache=0);
</cfscript>
Reply all
Reply to author
Forward
0 new messages