我想在CI模仿这些简单的PHP类定义最好的方式来实现标准的PHP类CI中与控制器
<?php
class Student
{
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
class SportsStudent extends Student {
private $sport;
public function __construct($name) {
parent::__construct($name);
$this->sport = "Tennis";
}
public function getSport() {
return $this->sport;
}
}
$s1 = new Student("Joe Bloggs");
echo $s1->getName() . "<br>";
$s2 = new SportsStudent("John Smith");
echo $s2->getName() . "<br>";
echo $s2->getSport() . "<br>";
?>
我想知道如何最好地接近它,我曾尝试创建这两个类的控制器,但有继承问题,我被告知最好是扩展CI_Controller,但无法让我的头,它似乎矫枉过正,不被推荐。
最好只保留这些标准类并从我的控制器中调用它们?
这是我第一次在系统中尝试使用MVC,也是我第一个CI项目,很高兴有一些指针。
请在问题中包含代码示例(尤其是相对较短的代码),而不是通过对该页面的未来访问者可能不适用的链接;-) – DaveRandom