Variables are not passing in view from my controller |
The Controller:
PHP Code: class Upload extends CI_Controller The View: PHP Code: <?php PHP Code: <?php echo form_open_multipart('upload/do_upload');?> Code: <input type="file" name="userfile" size="20" /> The Error: A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: core/Loader.php(830) : eval()'d code Line Number: 8 What is the Problem??
Your code should be in the index function/method not the __construct()
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Look carefully there is no code in my __construct(). My code is in function do_upload() of upload controller
The array: $data is exploded before passing to the view. Only the array elements are exposed to the view, which is why the reported error is: "Undefined variable:"
Code: <?php Comment the line as shown above and test again.
CI 3.1 Kubuntu 19.04 Apache 5.x Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing. Clarity is desirable over Brevity every time.
Try changing your do_upload like this:
PHP Code: public function do_upload() Then, in your view: PHP Code: if (empty($upload_data)) { Most of the changes are just cleanup, but, in general, I would avoid using the same variable name ($data) to reference multiple things, and I would avoid nesting arrays where it isn't necessary. Additionally, empty() or isset() help to avoid undefined variable errors when checking viewdata (though you have to be careful with empty(), especially if you pass boolean values to a view). The same warning applies to using $variable != "" instead of $variable !== "".
|
Welcome Guest, Not a member yet? Register Sign In |