Welcome Guest, Not a member yet? Register   Sign In
codeigniter, $this-> property not available in 1 method after being set in another
#4

[eluser]solvo[/eluser]
Hey Bill,

It looks to me like you're getting the row and setting it inside a controller method, then building the page and sending the output to the browser. Then the user submits the form to the server, and you're expecting that the variable you set will still exist and have the value set in the previous call to the server?

If I have your question correct, then this will not work. Dynamically set variables only survive as long as the request to the server. Once your output is built and sent back to the browser, any variables you set will be gone from memory.

Instead, take that $row_id and send it to your view. You can then set a hidden input in your form named "row_id" to the value of the $row_id. Now when the form builds in the user's browsers, that value will still exist. When they submit the form, one of the fields will be "row_id", and assuming they haven't modified your form (which is a terrible assumption to make, but for now we'll run with it), then the method that processes your form will have that value you're looking for.

Might look something like this:

Code:
class Main extends CI_Controller {
    function __construct()
    {
        parent::__construct();
        //Do what you need to here
    }

    function display_upload_form($row)
    {
        $this->load->view('upload_form', array('row_id' => $row, 'error' => '' ));
    }

    function do_upload()
    {
        $row_id = $this->input->post('row_id');
        var_dump($row_id);
    }
}

Your upload form should then contain something like this:

Code:
<input type="hidden" name="row_id" id="row_id" value="<?=$row_id?>" />

Alternatively, you can have the link you post your form to have the row_id in the URL, so that row_id value will get passed as a parameter to the do_upload() method.

To do this, your form should ultimately look something like this:

Code:
<form method="POST" action="http://yoursite.com/main/do_upload/<?=$row_id?>">

And then your do_upload method will look like this:

Code:
function do_upload($row_id)
{
    var_dump($row_id);
}


...this is all assuming I interpreted your problem correctly, of course.


Messages In This Thread
codeigniter, $this-> property not available in 1 method after being set in another - by El Forum - 06-11-2012, 10:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB