小编Red*_*ent的帖子

使用未定义的常量 - 学习OOP PHP

未定义的常量问题不是一个新的问题,我已经尝试了谷歌,发现了一百万个答案,涉及缺少引号的数组,这不是我的解决方案.我正在学习使用PHP进行OOP编码,这实际上是我使用它的前几个小时.这是我创建的课程.

class template {

var $page;

function __construct() {
    $this->page = 'home';
}

function getHeader($header = 'header') {
    include ('template/'.$header.'.php');
}

function getFooter($footer = 'footer') {
    include ('template/'.$footer.'.php');
}

function setPage($page = 'home') {
    $this->page = $page;
}

function getPage() {
    if(page === 'home') {
        include('template/home.php');
    } else {
        include('template/'.$this->page.'.php');
    }
}



}
Run Code Online (Sandbox Code Playgroud)

这就是我实例化它的方式.

include('class.template.php'); 

$template = new template();

$template->getHeader();

if(isset($_GET['page'])) {
    $template->setPage($_GET['page']);
}

$template->getPage();



$template->getFooter();
Run Code Online (Sandbox Code Playgroud)

当然还有错误 - 注意:使用未定义的常量页面 - 在第24行的/Applications/MAMP/htdocs/titan-up/class.template.php中假定为'page'

这显然是我应该立刻发现我做错了但现在已经很晚了,我不知所措.任何帮助是极大的赞赏.

编辑:非常感谢任何使学习过程更容易的链接.我已经阅读了PHP手册,并且拥有PHP的强大背景,但不是OOP.

php oop

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

MySQL语法错误

$sql = "UPDATE galleries SET name='$name', desc='$desc', mainthumb='$mt' 
        WHERE id='$id'";
Run Code Online (Sandbox Code Playgroud)

这引起了一些错误的理由.我一定太累了,因为我没有看到它.

我已确认所有值都已发布.更糟糕的是,它几乎完全复制任何查询工作正常.

更新:

这已经解决了.这是事实,desc没有反引号.我也将按照建议使用PDO.

php mysql

0
推荐指数
2
解决办法
84
查看次数

标签 统计

php ×2

mysql ×1

oop ×1