我正在使用 CakePhp 2.2.3 并且正在制作一个组件。
零件:
App::uses('Component', 'Controller');
class ExampleComponent extends Component {
public $settings = array();
protected $_defaults = array(
'a1' => null,
'a2' => 2
);
public function __construct(ComponentCollection $collection, $settings = array()) {
$settings = array_merge($this->_defaults, $settings);
$this->settings = $settings;
}
public function sum() {
$sum = $this->settings['a1'] + $this->settings['a2'];
return $sum;
}
}
控制器:
class ExampleController extends AppController {
public $components = array('Example');
public function index () {
$this->set('sum', $this->Example->sum(array('a1' => 2, 'a2' => 3)));
}
}
结果我回来了 (int) 2 。但我认为应该是5。我做错了什么?