0

I need to use some functions in CI controller.

For example:

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

But I get an error. How to determine these functions?

3
  • 1
    What errors are you getting and what version of CI are you using? Also, what is your actual code? Commented Nov 13, 2012 at 7:21
  • What are you want to determinate? Commented Nov 13, 2012 at 7:25
  • Where (specifically) did you define the functions? Commented Nov 13, 2012 at 7:32

2 Answers 2

1

As long as foo1 and foo2 are in the same controller you can do this:

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

    public function foo1()
    {
    }

    public function foo2()
    {
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

If you use the function declaration syntax inside another function, the inside function will end up in the current namespace (or the global namepsace if no namespace was declared)

consider this example:

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.