2012-12-18 33 views
2

我使用剛剛安裝CI 2.1.3 繼phpacademy教程中,我在routes.php文件中寫道:500錯誤在笨函數調用

(的
$route['default_controller'] = "site"; 

代替:$路線[ 'default_controller'] = 「歡迎」;)

和控制器/ site.php:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class Site extends CI_Controller { 
     public function index() { 
     echo "default function started.<br/>"; 

     } 
     public function hello(){ 
     echo "hello function started.<br/>"; 
     } 
} 

上傳到服務器,並進入[www.mydomain.ext]它的工作原理確定後(寫道:「默認功能開始「。 )但是如果我添加'this-> hello();'到index()函數它會引發500錯誤。

爲什麼會發生,我該如何解決?

預先感謝您。

+1

那麼最準確的方法來找出什麼地方出了錯將檢查服務器的日誌文件,如果你有機會到他們。雖然我覺得很難相信一個簡單的方法調用會導致這樣大小的錯誤。 – brezanac

回答

2

您是否正在將this->hello();添加到您的索引功能或$this->hello();

$this->hello();應該工作正常(測試):

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Site extends CI_Controller { 
     public function index() 
     { 
     echo "default function started.<br/>"; 
     $this->hello(); 
     } 

     public function hello() 
     { 
     echo "hello function started.<br/>"; 
     } 
} 
+0

成爲這樣一個noob ...這是尷尬的...謝謝你,sbeliv :) –