2012-11-13 102 views
0

我需要在CI控制器中使用一些功能。CodeIgniter控制器中的用戶功能

例如:

class Main extends Controller 
{ 
    function index() 
    { 
     function foo1(){} 
     function foo2(){} 
    } 
} 

但我得到一個錯誤。如何確定這些功能?

+2

你得到什麼錯誤? – Dinesh

+1

你收到了什麼錯誤,你使用的是什麼版本的CI? 另外,你的實際代碼是什麼? – Kenzo

+0

你想確定什麼? – complex857

回答

1

只要foo1和foo2的是在同一個控制器,你可以這樣做:

class Main extends Controller 
{ 
    function index() 
    { 
     $this->foo1(); 
     $this->foo2(); 
    } 

    public function foo1() 
    { 
    } 

    public function foo2() 
    { 
    } 
} 
0

如果您使用的函數聲明語法另一個函數裏面,裏面的功能將在當前命名空間中結束(或如果沒有命名空間被宣佈爲全球namepsace)

考慮這個例子:

Class Foo { 
    public function bar() { 
     function foo(){ 
      print 'in foo'; 
     } 
    } 
} 

$f = new Foo(); 
$f->bar(); // you have to call this before invoking the foo() function, prior this point its nonexistent 
foo(); // will print 'in foo' 
相關問題