CodeIgniter Forums
notice driving me crazy - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: notice driving me crazy (/showthread.php?tid=25540)



notice driving me crazy - El Forum - 12-15-2009

[eluser]amipaxs[/eluser]
hello buddies,

this

Code:
<?php
class Portal extends Controller {

  public $data;
  function Portal()
   {
    parent::Controller();
    $data['poll'] = $this->MEncuestas->displayPoll(); // load question.
    extract($data['poll']); // extract id from poll.
          
    $data['options'] = $this->MEncuestas->displayOptions($id); //(I get undefined index id )

while in the localhost it doesn't show any notice msg, but when i upload the files to the server I get the undefined index id message.. so how can i correctly extract the $id from the $data['encuesta'] array and use it in the second query?

thanks in advance


notice driving me crazy - El Forum - 12-15-2009

[eluser]kilishan[/eluser]
I'm not convinced that's your problem. It sounds to me like the extract command is not finding any data to extract. Are you sure that you're getting a good poll back on the live server?


notice driving me crazy - El Forum - 12-16-2009

[eluser]LuckyFella73[/eluser]
Did you try to access the id this way?:
Code:
$data['options'] = $this->MEncuestas->displayOptions($data['poll'][id]);
I just read that the extract function doesn't behave the same on all servers,
so it could be more save to access the value this way.

Your error message says that the variable $id is not available/ defined,
so first I would echo the variable to see if there is any data.

In your case:
Code:
<?php
class Portal extends Controller {

  public $data;
  function Portal()
   {
    parent::Controller();
    $data['poll'] = $this->MEncuestas->displayPoll(); // load question.
    extract($data['poll']); // extract id from poll.
    echo('<h1>My ID is: '.$id.'</h1>');
    #$data['options'] = $this->MEncuestas->displayOptions($id); //(I get undefined index id )

In case your script does not echo any id value I would check your method.

If register globals is not activated on your server than you can get this problems
especially when extracting $_FILES array. Have a look at http://php.net/manual/en/function.extract.php NOTES section for further details.


notice driving me crazy - El Forum - 12-16-2009

[eluser]BrianDHall[/eluser]
Probably a silly question as I've never had a use for extract(), but why use it at all? $data['poll']['id'] is much clearer, as originally when I read over your code I couldn't figure out where $id was coming from.

I would try a var_dump($data['poll']) to see what is up with the structure, it is likely that it is not the structure you are expecting.

Generally extract() makes things harder to debug.

And in your index.php, check to see that you have this:

Code:
/*
|---------------------------------------------------------------
| PHP ERROR REPORTING LEVEL
|---------------------------------------------------------------
|
| By default CI runs with error reporting set to ALL.  For security
| reasons you are encouraged to change this when your site goes live.
| For more info visit:  http://www.php.net/error_reporting
|
*/
    error_reporting(E_ALL);

It will show notices in localhost, so you don't have to wait until you upload to see notices and warnings and such.


notice driving me crazy - El Forum - 12-16-2009

[eluser]John_Betong[/eluser]
&nbsp;
>>> It will show notices in localhost, so you don’t have to wait
>> until you upload to see notices and warnings and such.
&nbsp;
If on the off-chance it does not show any errors then use the following line:
Code:
ini_set('display_errors',  'On');
&nbsp;
&nbsp;


notice driving me crazy - El Forum - 12-16-2009

[eluser]amipaxs[/eluser]
finally I got rid of the extract method to get the id from the poll array,

now it works perfectly this way:


Code:
$data['options'] = $this->MEncuestas->displayOptions($data['poll']['id']);

by the way, error_reporting(E_ALL) was always active in the localhost, only once i uploaded the file i got
the notices about the undefined index , strange!

Thanks a lot!