30

I am trying to do this code in my CodeIgniter application :

class Inventory extends Controller
{

    function current_stock()
    {
        //do something
    }

    function add_stock()
    {
        //do something-else
        ****then do function current_stock()*****
    }
}

How do I execute another method from within a second one? The approach outlined here (about extending controllers) is something of an overkill for me.

Am I missing a much easier way?

1

3 Answers 3

107

OK, I agree this is a MAJOR goof-up; comes from lack of OOP understanding;

<?php
class Inventory extends Controller {
    function current_stock() {
        //do something
    }

    function add_stock() {
        //do something-else
        $this->current_stock();
        // and we called the other method here!
    }
}

Just that I didn"t expect it to be so easy

Sign up to request clarification or add additional context in comments.

Comments

8

Just use $this->your_function_name();

Comments

4

Only $this->nameFunction();
example

<?php 

class Hello extends CI_Controller{

 public function index(){
  $this->hello();
 }
public function hello(){
  return "hello world";
 }
}

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.