我有一个错误,我不知道我做错了什么。请帮忙:)所以,我有一个名为活动的类,其中我有几个函数,如下所示:
class Activities
{
public $content = null;
public function __construct( $data=array() ) {
if ( isset( $data['content'] ) ) $this->content = $data['content'];
}
public function storeFormValues ( $params ) {
$this->__construct( $params );
}
public static function getData() {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT * FROM exceptions WHERE name = 'atrakcje'";
$st = $conn->prepare( $sql );
$st->execute();
$row = $st->fetch();
$conn = null;
if ( $row ) return new Activities( $row );
}
public function update() {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "UPDATE exceptions SET content=:content WHERE name = 'atrakcje'";
$st = $conn->prepare ( $sql );
$st->bindValue( ":content", $this->content, PDO::PARAM_STR );
$st->execute();
$conn = null;
}
}
我在我制作的小管理面板中有一个函数 editActivities() :
function editActivities() {
$results = array();
$results['pageTitle'] = "Edytuj Atrakcje";
$results['formAction'] = "editActivities";
if ( isset( $_POST['saveChanges'] ) ) {
$activities->storeFormValues( $_POST );
$activities->update();
header( "Location: admin.php?action=editActivities&status=changesSaved" );
} elseif ( isset( $_POST['cancel'] ) ) {
header( "Location: admin.php?action=editActivities" );
} else {
$results['activities'] = Activities::getData();
require( TEMPLATE_PATH . "/admin/editActivities.php" );
}
}
我也有一个 HTML 表单来进行更改。但是当我提交填写好的表格时,我收到一个错误:
Fatal error: Call to a member function storeFormValues() on a non-object in C:\xampp\htdocs\admin.php on line 285
我的代码中的 285 行在这里:
if ( isset( $_POST['saveChanges'] ) ) {
$activities->storeFormValues( $_POST );
$activities->update();
我不知道发生了什么事。我有相同的代码来编辑其他文章和用户,但我不知道这里有什么不好。谢谢你的帮助!