2012-11-13 34 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' 
相关问题