小编dim*_*ech的帖子

为什么我在这里得到未定义的变量错误?

我在tpl.php文件中有这段代码

<?php foreach ($images as $image): ?>
  <?php print $image ."\n"; ?>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)

我在预处理功能中有以下内容

function preprocess(&$vars) {
  // Initialize our $images array.
  $vars['images'] = array();

  foreach ($vars['rows'] as $item) {
    if (preg_match('@(<a.*?img.*?</a>)@i', $item, $matches)) {
      $image = $matches[1];
    }
    elseif (preg_match('@(<\s*img\s+[^>]*>)@i', $item, $matches)) {
      $image = $matches[1];
    }
    else {$images = NULL;}
    // Add the image to our image array
    $vars['images'][] = $image;
  }
Run Code Online (Sandbox Code Playgroud)

未定义的变量:预处理函数中此行的图像

  $vars['images'][] = $image;
Run Code Online (Sandbox Code Playgroud)

php drupal

1
推荐指数
1
解决办法
1150
查看次数

标签 统计

drupal ×1

php ×1