php 在 Codeigniter 的控制器上的函数 B 中调用函数 A
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19701317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:53:40 来源:igfitidea点击:
Call function A inside function B on Codeigniter's controller
提问by Vaibhav Singhal
I have a controller that have about 5-6 functions.
我有一个大约有 5-6 个功能的控制器。
class Register extends CI_Controller {
public function index()
{
// some code written
}
public function Add()
{
// Some code written
}
public function xyz()
{
// Some code written
$this->abc();
}
public function abc()
{
// Some code written
}
}
In xyz
function, i want to call abc
function.
Is this possible ? if so, how to call it ?
在xyz
函数中,我想调用abc
函数。这可能吗 ?如果是这样,如何称呼它?
回答by Saravanan
It is possible, the code you have written is correct
有可能,你写的代码是正确的
public function xyz()
{
// Some code written
$this->abc(); //This will call abc()
}
EDIT:
编辑:
Have you properly tried this?
你有没有正确尝试过这个?
class Register extends CI_Controller {
public function xyz()
{
$this->abc();
}
public function abc()
{
echo "I am running!!!";
}
}
and call register/xyz
并打电话 register/xyz