我有一个简单的模型,它添加了2个作为参数给出的数字,但是看起来内置函数add()没有被识别。
这是模型
<?php
class SimpleMaths extends CModel{
private $numberone;
private $numbertwo;
public function SimpleMaths($numberones,$numbertwos){
$numberone = $numberones;
$numbertwo = $numbertwos;
}
public function add()
{
return $numbertwo + $numberone;
}
public function attributeNames(){
return array('number 1' => $numberone, 'number 2'=> $numbertwo);
}
}
?>
这是控制器:
<?php
class BlogController extends Controller{
public function actionIndex(){
$none = $_GET['n1'];
$ntwo = $_GET['n2'];
$model = new SimpleMaths($ntwo,$none);
// $sum = $model.add();
$array = get_class_methods('SimpleMaths');
$this->render("index",array("interesting"=>$array,"model"=>$model));
}
}
?>
这是视图
<?php
echo "Hello World";
foreach($interesting as $one)
{
echo $one."<br>";
echo "<hr>";
echo $model.add();
}
?>
add函数被显示为其中一个函数,但是当调用时,它只是隐藏自己?
错误如下:
Fatal error: Call to undefined function add() in C:\wamp\www\testdrive\protected\views\blog\index.php on line 8