Undefined index php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NicoCaldo
Forum Newbie
Posts: 2
Joined: Tue Jun 12, 2012 1:36 am

Undefined index php code

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index php code

Post 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.
Last edited by social_experiment on Tue Jun 12, 2012 4:02 am, edited 1 time in total.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Undefined index php code

Post 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;
    }
}
Post Reply