Php方法未被调用

时间:2015-11-23 16:15:19

标签: php html5 methods

我一直在尝试调试此代码一段时间,看起来没有调用build方法。我把echo,var_dumps和所有其他类型的符号放在其中,但从来没有得到任何东西。

完整的PHP代码

class Auto_slideshow {

  private $_img_dir;

  //constructor sets directory containing the images
  function __construct($dir) {
    //Directory source from webroot
    $_img_dir = $dir;
  }

  //Iterates through directory and constructs HTML img list
  public function build() {

    //use SPL for directory iteration
    $iterator = new DirectoryIterator($_img_dir);

    $html = '';
    $i = 1;

    //Iterate through directory
    foreach ($iterator as $file) {

      //set a variable to add class of "show" on first element
      $showClass = $i === 1 ? ' class="show"' : null;

      //exclude '.' and '..' files
      if(!$iterator->isDot()) {

        //set src attribute for img tag
        $src = $_img_dir . $iterator->getFilename();

        //Grab sizes of images
        $size = getimagesize($_img_dir . $iterator->getFilename());
        var_dump($src);
        //create img tags
        $html .= '<img src="' . $src . '" ' . $size[3] . $displayNone . ' />' . "\r\n";

        $i++;
      }
    }

    return $html;
  } 
}

html调用

<center>
    <div class="imagecontainer" id="auto-slideshow">
    <?php
    $show = new Auto_slideshow("../CMSC/images/master/slidestock/");
    $show->build();
    ?>
</div>
</center>

我也尝试print $show->build();the tutorial显示,但也没有效果。

更新

我将$_img_dir更改为$this->$_img_dir' and called the method by echo show-&gt; build();`并且该方法仍未被调用。

这是一个甚至没有运行的方法,甚至还没有找到图像。

更新2

如果我删除html中的整个PHP代码,页面的其余部分加载就好了。就像现在一样,html只加载到包含php的div然后停止它之后的所有内容。

0 个答案:

没有答案
相关问题