Codeigniter调用函数在同一个类中

时间:2023-01-02 16:45:37

I am trying to do this code in my Codeigniter application

我想在我的Codeigniter应用程序中执行此代码

<?php
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 function 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?

我错过了一个更简单的方法吗?

3 个解决方案

#1


93  

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

好的,我同意这是一个主要的蠢事;来自缺乏OOP理解;

<?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

只是我没想到它会如此简单

#2


7  

Just use $this->your_function_name();

只需使用$ this-> your_function_name();

#3


1  

Only $this->nameFunction();
example

只有$ this-> nameFunction();例

<?php 

class Hello extends CI_Controller{

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

#1


93  

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

好的,我同意这是一个主要的蠢事;来自缺乏OOP理解;

<?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

只是我没想到它会如此简单

#2


7  

Just use $this->your_function_name();

只需使用$ this-> your_function_name();

#3


1  

Only $this->nameFunction();
example

只有$ this-> nameFunction();例

<?php 

class Hello extends CI_Controller{

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