我对PHP很陌生,我正在使用Codeigniter。我有一个PHP文件,并以OOP的形式执行了以下操作:
<<!DOCTYPE html>
<?php
class Producat
{
var $price;
var $title;
var $name;
public function setProducatName ($nam)
{
$this->name=$nam;
}
public function getProduactName()
{
echo $this->name;
}
public function setAttribute ($price1,$title1)
{
$this->price=$price1;
$this->title=$title1;
}
class Fruniture extends Producat
{
var $size;
var $material;
}
class Cddvd extends Producat
{
var $size;
var $manufacuter;
}我的phpmyadmin中有一个名为saied的数据库。
我正在尝试将产品的标题插入到数据库中,然后从类中的数据库中获取名称。
注意:我完成了连接到数据库的所有配置。
发布于 2016-05-14 13:59:16
你失去了神奇的__construct函数
http://php.net/manual/en/language.oop5.decon.php
发布于 2016-05-14 14:08:42
这不是使用CI php框架的确切方式。首先,你需要了解基本知识。
示例主计长:
<?php
class Product extends CI_Controller {
public function index()
{
echo 'Hello World!';
$this->load->view("products");
}
}
?>示例模型:
class Product extends CI_Model {
var $title = '';
var $content = '';
var $date = '';
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_all()
{
$query = $this->db->get('entries');
return $query->result();
}
}发布于 2016-05-14 14:09:23
<<!DOCTYPE html>代码大部分是这样的:
<?php
class Producat extends CI_Model
{
var $price;
var $title;
var $name;
function __construct($price1,$title1) {
parent::__construct();
$this->price=$price1;
$this->title=$title1;
}
public function setProducatName ($nam)
{
$this->name=$nam;
}
public function getProduactName()
{
return $this->name;
}
public function setAttribute ($price1,$title1)
{
$this->price=$price1;
$this->title=$title1;
}
function insert_indb(){
$data[] = ["title"=>$this->title];
$data[] = ["name"=>$this->name];
$data[] = ["price"=>$this->price];
$this->db->insert('students', $data);
}https://stackoverflow.com/questions/37227550
复制相似问题