cakephp2.x组件无法正常工作

pay*_*ike 1 components cakephp

我像这样创建我的组件

<?php
class UtilComponent extends Object
{
   function strip_and_clean( $id, $array) {
      $id = intval($id);
     if( $id < 0 || $id >= count($array) ) {
        $id = 0;
     }
      return $id;
   }
}
Run Code Online (Sandbox Code Playgroud)

并像这样使用它

var $name = 'Books';
    var $uses = array();
    var $components = array('Util');
    public function index($id = 0){
        $this -> set('page_heading','Packt Book Store');
        $book=array(
            '0'=>array(
                'bookTitle'    =>'Object Oriented Programming with PHP5',
                'author'       =>'Hasin Hayder',
                'isbn'         => '1847192564',
            'releaseDate' => 'December 2007'
                ),
            '1'=>array(
                'bookTitle'    =>'Building Websites with Joomla! v1.0',
                'author'       =>'Hagen Graf',
                'isbn'         => '1904811949',
            'releaseDate' => 'March 2006'
                ),
            );
        $id = $this->Util->strip_and_clean( $id, $book);
        $this->set('book',$book[$id]);
        $this->pageTitle='Welcome to the Packt Book Store!';
    }
Run Code Online (Sandbox Code Playgroud)

但我得到了这个错误

**call_user_func_array() 期望参数1是有效的回调,类'UtilComponent'没有方法'initialize'[CORE\Cake\Utility\ObjectCollection.php,第130行]**

Dou*_*ngs 7

我相信一个组件应该扩展Component不是Object:

class UtilComponent extends Component 
{

}
Run Code Online (Sandbox Code Playgroud)

然后该组件将继承该initialize()方法.