2012-07-17 49 views
0

試圖儘可能具體,因爲我上次猛烈抨擊我發佈了一些東西!cakephp 2.0致命錯誤:調用一個非對象的成員函數sort()

用戶身份驗證,然後在AppController的我的路線他們用行動幸福指數代碼控制器稱爲業主下面

public $components = array(                   
    'Session',                      
    'Auth' => array(                    
    'loginRedirect' => array('controller' => 'Owners', 'action' => 'index')      
)  

我是新來的蛋糕,但我的猜測是,當所有者控制器觸發代碼索引函數,它什麼都不返回,這就是爲什麼我在視圖中得到致命的錯誤信息。 (我正在閱讀Cakephp 2.0食譜),並且所有者表中有多個所有者,因此它不是空的。

mysql> select * from owners;
+ ---- + ----------- + ------------- + ---------- + ----- --------------- + ---------- + --------- + ------- + ----- - ------ + --------- + ------------ + ------------- +
| id |名字| middlename |姓氏| streetaddress |城市|郵編|狀態| phonen umber | user_id | vehicle_id | citation_id |
+ ---- + ----------- + ------------- + ---------- + ----- --------------- + ---------- + --------- + ------- + ----- - ------ + --------- + ------------ + ------------- +
| 1 | Mark | Walter |辛普森| 1234 Anytown | antonw | 12345 | Ge | 916123 456 | 1 | NULL | NULL |
| 2 |弗蘭克| Dorthmuller |弗蘭克| 2857 Bonlay Street |弗雷斯諾| 95758 | Ca | 916551 0234 | 3 | NULL | NULL |
| 3 |託倫| W | Valone | 8252盲櫟方式| Belfower | 3889 | ca | 917838 8 | 1 | NULL | NULL |
| 4 |託倫| W | Valone | 8252盲櫟方式| Belfower | 3889 | ca | 917838 8 | 1 | NULL | NULL |
+ ---- + ----------- + ------------- + ---------- + ----- --------------- + ---------- + --------- + ------- + ----- - ------ + --------- + ------------ + ------------- +
4在集中的行(0.00秒)

在所有者控制器I把這個下面的代碼索引功能,

 public function index() {                 

      $this->set('owners', $this->Owner->find('all'));          
    } 

當我登錄作爲用戶I得到這個, 業主

通知( 8):未定義的屬性:View :: $ Paginator [CORE/Cake/View/View .php,line 804]

致命錯誤:調用/srv/www/www.cross-town-traffic-software.com/public_html/freecite/app/中的非對象的成員函數sort()第5行

這裏查看/業主/ index.ctp是從業主目錄中的文件index.ctp五線

<th><?php echo $this->Paginator->sort('id');?></th>  

回答

2

您正在嘗試使用PaginatorHelper在您的視圖,但不包括它。

添加

public $helpers = array('Paginator'); 

到控制器。 See Cookbook for background on Helpers以及如何在您的視圖中使用它們。

+1

所以控制器?現在我得到警告(2):array_filter()期望參數1是數組,null給出和致命錯誤:不能使用字符串偏移作爲數組在/srv/www/www.cross-town-traffic-software.com/第19行的public_html/freecite/app/View/Owners/index.ctp – user1522265 2012-07-17 22:05:07

+0

當我從控制器中刪除索引函數並放回腳手架時,我得到一個包含所有所有者和操作的頁面。我確實留下了幫手,並沒有收到任何錯誤消息。 – user1522265 2012-07-17 22:22:46

+0

它與'index()'函數無關,'$ helpers'是Controller類的成員,就像'$ components'一樣。如果您想在視圖中使用助手,則需要將其包含在相應的控制器中。就這樣。關於你的下一個錯誤信息:很難說,沒有看到你的文件的第19行... – pixelistik 2012-07-18 08:30:57

0

在您需要的時候你重寫你必須添加分頁程序幫助索引功能添加

public $components = array('Paginator'); 

代替

public $helpers = array('Paginator'); 
相關問題