Page 1 of 1

Undefined index php code

Posted: Tue Jun 12, 2012 1:44 am
by NicoCaldo
I have a CMS and I'm trying to run an extension based on php. I just get this error

Notice: Undefined index: in apps_server_local screenshots () (line 23 of / web / htdocs / http://www.wite.it / home / drupal / sites / all / modules / apps / apps.manifest.inc).

I tried to control the sheet of php and line 23 is

Code: Select all

foreach ($ app ['screenshots'] as $ id => $ image) {
But I can not understand the problem.
I pass the entire function so that they understand better

Code: Select all

define("APPS_ENABLED", 1);
define("APPS_DISABLED", 0);
define("APPS_INCOMPATIBLE", -1);
define("APPS_INSTALLABLE", 2);


function apps_server_local($server) {
  $apps = array();
  $infos = system_rebuild_module_data();
  foreach($infos as $module => $info) {
    if(isset($info->info['apps']['server'])) {
      if($info->info['apps']['server'] = $server['name']) {
        foreach($info->info['apps']['manifests'] as $mfile) {
          $mfile = drupal_get_path("module", $module) . "/" .$mfile;
          $app = drupal_parse_info_file($mfile);
          foreach($app['screenshots'] as $id=>$image) {
            $app['screenshots'][$id] = url(dirname($mfile) . "/" . $image);
          }
            $app['logo'] = url(dirname($mfile) . "/" . $app['logo']);
          $apps[] = $app;
        }
      }
    }
  }
  return $apps;
}
Thanks for any help that you give me

Re: Undefined index php code

Posted: Tue Jun 12, 2012 3:54 am
by social_experiment

Code: Select all

foreach ($ app ['screenshots'] as $ id => $ image)
why the spaces between $ and the variable name? remove the spaces and see if the problem persits

EDIT
scratch my theory.

Re: Undefined index php code

Posted: Tue Jun 12, 2012 3:57 am
by twinedev
It is probably due to that for part of the data there is no array element called 'screenshots'. You can check to see if there is by wrapping it with the following:

Code: Select all

if (isset($app['screenshots'])) {
    foreach ($app['screenshots'] as $id=>$image) {
        $app['screenshots'][$id] = url(dirname($mfile) . '/' . $image;
    }
}