Welcome Guest, Not a member yet? Register   Sign In
Redirct to another method and keep public class property?
#1

[eluser]john36122340[/eluser]
Hi everyone,

I was wondering why this code does not work, I thought if I set a property of the class and then redirected to another method in that class the property would still be available in another method.

Does anyone have any ideas?

Is it possible without flashdata?

Thanks,

John

Code:
function method_one()
    {
        $this->some_var = 'Susan';
        redirect( '/welcome/method_two' );
        printf('<p>This is the first printf from method_one</p>');
    }
    
    function method_two()
    {
        printf('<p>This is the first printf from method_two</p>');
        printf('<p>This is the value of some_var "%s" set in method_one</p>', $this->some_var);
        $this->some_var = 'Bill';
        printf('<p>This is the value of some_var "%s" set in method_two</p>', $this->some_var);
    }

Outputs:

Code:
This is the first printf from method_two
This is the value of some_var "" set in method_one //Why is $this->some_var = 'Susan' not available here?
This is the value of some_var "Bill" set in method_one
#2

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
Redirects wouldn't maintain the same instance of the class, as it's a new request to the server. You probably want to call the other method like this:

Code:
$this->method_two();

That should do the trick.
#3

[eluser]john36122340[/eluser]
Thanks for the reply jeremygimbel,

What would be the best way to run method_two() and stop the execution of the script?
OR
Is there any way to redirect and keep data, am I in flashvars territory???

Thanks,

John
#4

[eluser]john36122340[/eluser]
Howdy guys,

Been reading a couple of posts in the forum, would HMVC do this for me easily???




Theme © iAndrew 2016 - Forum software by © MyBB