PHP if语句的问题

时间:2015-03-30 12:24:14

标签: php if-statement plugins

我一直在尝试使用php设置插件。 php文件只是注册插件。问题是我想在插件中包含一些图像文件,但插件没有提取它。当插件安装时我没有看到图像文件,我实际上不知道php这只是一个我需要为更大的项目编译的文件。

<?php

class Plugin_Theme extends DPlugin
{

    public function init()
    {
        DTheme::register($this, $this->getMeta('theme1', 'theme1'));
        DTheme::register($this, $this->getMeta('theme2', 'theme2'));
        DTheme::register($this, $this->getMeta('theme3', 'theme3'));
        DTheme::register($this, $this->getMeta('theme4', 'theme4'));
    }

    private function getMeta($sub_id, $sub_name, $extends = 'default')
    {
        $meta = array (
            'id' => 'maintheme-' . $sub_id,
            'title' => 'maintheme-' . $sub_name,
            'extends' => $extends,
        );
        if ($sub_id != 'theme1') {
            $meta['assets'] = array(
               0 => 'image1.jpg',
               1 => 'image1.jpg',);
        }
        if ($sub_id != 'theme2') {
            $meta['assets'] = array(
                0 =>'image2.jpg',
                1 =>'image2.jpg',);
        }
        if ($sub_id != 'theme3') {
            $meta['assets'] = array(
                0 => 'image3.jpg',
                1 => 'image3.jpg',);
        }
        if ($sub_id != 'theme4') {
            $meta['assets'] = array(
                0 => 'image4.jpg',
                1 => 'image4.jpg',);
        }

        return $meta;
    }
}

错误 无法加载未找到的资源404。

1 个答案:

答案 0 :(得分:0)

试试这个

<?php
class Plugin_Theme extends DPlugin
{

    public function init()
    {
        DTheme::register($this, $this->getMeta('theme1', 'theme1'));
        DTheme::register($this, $this->getMeta('theme2', 'theme2'));
        DTheme::register($this, $this->getMeta('theme3', 'theme3'));
        DTheme::register($this, $this->getMeta('theme4', 'theme4'));
    }

    private function getMeta($sub_id, $sub_name, $extends = 'default')
    {
        $meta = array (
            'id' => 'maintheme-' . $sub_id,
            'title' => 'maintheme-' . $sub_name,
            'extends' => $extends
        );
        if ($sub_id != 'theme1') {
            $meta['assets'] = array(
               0 => 'image1.jpg',
               1 => 'image1.jpg');
        }
        if ($sub_id != 'theme2') {
            $meta['assets'] = array(
                0 =>'image2.jpg',
                1 =>'image2.jpg');
        }
        if ($sub_id != 'theme3') {
            $meta['assets'] = array(
                0 => 'image3.jpg',
                1 => 'image3.jpg');
        }
        if ($sub_id != 'theme4') {
            $meta['assets'] = array(
                0 => 'image4.jpg',
                1 => 'image4.jpg');
        }

        return $meta;
    }
}

在数组末尾没有','