我是 PHP 的 OOP 新手,我正在尝试做这样的事情:类条目表单在它自己的文件中。index.php 从类条目表单创建一个对象并将其存储在会话中。page1.php - 我希望能够回调这个对象并在其上运行一些方法来修改它的值。除了这不起作用...
所以工作流程如下index->page1
我试图掌握面向对象编程的概念。我开始明白了。我想做错了吗?这可能吗?
//page1.php
include('entry.class.php');
session_start();
print_r($_SESSION['entry']);
$entry = unserialize($_SESSION['Entry']);
$entry->set_category('Asian');
$entry->set_upload('http://paypal.com');
print_r($entry);
//index.php
session_start();
include('entry.class.php');
$entry = new entryForm();
$entry->set_category('Blondes');
$entry->set_upload('http://google.com');
$_SESSION['entry'] = serialize($entry);
print_r($entry);
print_r($_SESSION['entry']);
//class entryform
class entryForm{
var $category;
var $upload;
function set_category($new_category)
{
$this->category = $new_category;
}
function get_category()
{
return $this->category;
}
function set_upload($new_upload)
{
$this->upload = $new_upload;
}
function get_upload()
{
return $this->upload;
}
}