CakePHP:我如何从Model.php文件中获取所有函数名称?需要一个PHP脚本

时间:2011-12-15 09:09:49

标签: cakephp cakephp-2.0

如何从cakephp Model.php或者cakephp的其他文件中获取所有函数名称?

我不想浏览api网站。

我需要像这样显示功能名称..

public function query($sql)
public function validates($options = array())

我试过这个

<?php

require_once('Model.php');
$methods = get_class_methods('Model');
print_r($methods);

?>

但得到了错误

PHP Fatal error:  Class 'App' not found in /var/www/cakemyblog/lib/Cake/Model/Model.php on line 25
PHP Stack trace:
PHP   1. {main}() /var/www/cakemyblog/lib/Cake/Model/countfunction.php:0
PHP   2. require_once() /var/www/cakemyblog/lib/Cake/Model/countfunction.php:3

2 个答案:

答案 0 :(得分:4)

您需要实例化模型并传递对象本身:

require_once('Model.php');
$Model = new Model();
$methods = get_class_methods($Model);
print_r($methods);

但它不会给你参数。

修改

看起来你是从Cake外部运行的。您需要包含 Model 类依赖的所有类:

require_once 'lib/Cake/Core/App.php';
require_once 'lib/Cake/Core/Object.php';
require_once 'lib/Cake/Utility/ObjectCollection.php';
require_once 'lib/Cake/Model/BehaviorCollection.php';
require_once 'lib/Cake/Utility/Inflector.php';
require_once 'lib/Cake/Utility/ClassRegistry.php';
require_once 'lib/Cake/Model/Model.php';
$methods = get_class_methods('Model');
print_r($methods);

这给了你:

Array
(
    [0] => __construct
    [1] => __call
    [2] => __isset
    [3] => __get
    [4] => bindModel
    [5] => unbindModel
    [6] => setSource
    [7] => set
    [8] => deconstruct
    [9] => schema
    [10] => getColumnTypes
    [11] => getColumnType
    ...

答案 1 :(得分:1)

尝试在文件中使用get_class_methods