CodeIgniter call function within the same class

前端 未结 3 672
逝去的感伤
逝去的感伤 2020-12-24 13:35

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



        
相关标签:
3条回答
  • 2020-12-24 13:46

    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

    0 讨论(0)
  • 2020-12-24 13:46

    Just use $this->your_function_name();

    0 讨论(0)
  • 2020-12-24 13:50

    Only $this->nameFunction();
    example

    <?php 
    
    class Hello extends CI_Controller{
    
     public function index(){
      $this->hello();
     }
    public function hello(){
      return "hello world";
     }
    }
    
    0 讨论(0)
提交回复
热议问题