未定义的属性

时间:2014-06-14 15:36:56

标签: php undefined

我收到以下错误。 我无法弄清楚这段代码有什么问题。

有一些我错过或遗忘的东西。 任何人都可以帮帮我吗?我现在卡住了。

他一直在说数组的东西。

Notice: Undefined property: Cms::$contant_types in C:\xampp\htdocs\PassieCMS\app\cms\models\m_cms.php on line 34

Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\PassieCMS\app\cms\models\m_cms.php on line 34

<?php

/*
    CMS Class
    Handle CMS task, allowing admins to view/edit content
*/

class Cms
{
    private $content_types = array('wysiwyg', 'textarea', 'oneline');
    private $FP;

    function __construct()
    {
        global $FP;
        $this->FP = &$FP;   
    }

    function clean_block_id($id)
    {
        $id = str_replace(' ', '_', $id);
        $id = str_replace('-', '_', $id);
        $id = preg_replace("/[^a-zA-Z0-9_]/", '',$id);
        return strtolower($id); 
    }

    function display_block($id, $type = 'wysiwyg')
    {
        // clean id
        $id = $this->clean_block_id($id);

        // check for valid type
        $type = strtolower(htmlentities($type, ENT_QUOTES));
        if (in_array($type, $this->contant_types) == FALSE)
        {
            echo "<script>alert('Please enter a valid block type for \'" . $id . "\'');</script>";
            return;
        }

        // get content
        $content = "content here...";

        // check login status
        if ($this->FP->Auth-checkLoginStatus())
        {
            if($type == 'wysiwyg') { $type2 = 'WYSIWYG';}
            if($type == 'textarea') { $type2 = 'Textarea';}
            if($type == 'oneline') { $type2 = 'One Line';}

            $edit_start = '<div class=""fp_edit>';
            $edit_type = '<a class="fp_edit_type" href="' . SITE_PATH .'app/cms/edit.php?id' . $id . '&type='. $type . '">' . $type2 . '</a>';
            $edit_link = '<a class="fp_edit_link" href="' . SITE_PATH .'app/cms/edit.php?id' . $id . '&type='. $type . '">Bewerken</a>';
            $edit_end = '</div>';

            echo $edit_start . $edit_type;
            echo $edit_link . $content . $edit_end;
        }
        else
        {
            echo $content;
        }
    }
}   

并且索引文件是

<?php include ("app/init.php");?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PassieCMS</title>
<link href="resources/css/style.css" rel="stylesheet" type="text/css">
<?php $FP->head(); ?>
</head>

<body class="home <?php $FP->body_class(); ?>">

    <?php $FP->toolbar(); ?>

    <div id="wrapper">
        <h1>Website</h1>

        <div id="banner">
            <img src="resources/images/banner.jpg" alt="banner" width="900" height="140">
        </div>

        <ul id="nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">Test link</a></li>
            <li><a href="#">Longer Text Link</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>

        <div id="content">
            <div class="left">
                <h2><?php $FP->Cms->display_block('content-header','oneline'); ?></h2>
                <?php $FP->Cms->display_block('content-maincontent'); ?>
            </div>
            <div class="right">
                <?php $FP->Cms->display_block('content-quote'); ?>
                <?php $FP->Cms->display_block('content-attribution'); ?>
            </div>
        </div>

        <div id="footer">
            Copyright 2014 PassieCMS | <?php $FP->login_link();?> <a href="app/login.php">Login optie 2</a>
        </div>

     </div>

</body>
</html>

谢谢大家的时间

1 个答案:

答案 0 :(得分:0)

if (in_array($type, $this->contant_types) == FALSE)

你有一个拼写错误,你已将其声明为content_types以上。这应该有效:

if (in_array($type, $this->content_types) == FALSE)
相关问题