dsuikgi9199 2015-11-18 08:27
浏览 29

CodeIgniter:根据所选的控制器名称显示方法名称

I have 2 dropdown in one of my web page build with CodeIgniter. First dropdown is Controller Name and second one is Method Name. I am able to pull all controllers from controllers directory by using get_filenames() and showing their names in the dropdown option. Now when user choose a controller name from first dropdown I want to show all methods name declared on that model file in the second dropdown.

I'll do an ajax call and populate the second dropdown as per first dropdown selection. My question is how can I get methods name as per controller selected.

This is what I have tried. Note $data['controller'] is the controller name I'm posting via ajax. This is showing method name but it also showing method name of class from which I have extended my controller class. I only want the method names declared on the controller itself.

$myClass = require_once($this->config->item('APP_FULL_PATH').'controllers/' . $data['controller'] . ".php"); 
print_r(get_class_methods(new $data['controller']()));

Any idea how to do that!

  • 写回答

1条回答 默认 最新

  • douao1858 2015-11-18 08:33
    关注

    Your close - include the class you want to call then do this;

    $class_methods = get_class_methods('myclass');
    // or
    $class_methods = get_class_methods(new myclass());
    
    foreach ($class_methods as $method_name) {
        echo "$method_name
    ";
    }
    

    For CodeIgniter do this;

    get_class_methods($this);
    

    So an example is;

    class myclass extends CI_Controller {
    
      public function __construct() {
    
                parent::__construct();
    
                var_dump(get_class_methods($this));
            }
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法