33# TODO
44# AUTO-GENERATING MY_MODELS
55
6- $ my_models = " * " ;
6+ static $ my_models = " * \n" ;
7+
8+ $ app_path = dirname (dirname (dirname (dirname (dirname (dirname (__FILE__ )))))) . '/application/models ' ;
9+
10+ work ($ app_path , $ my_models );
711
812$ my_models_tpl = <<<MY_MODELS_TPL
913<?php die();
@@ -29,4 +33,36 @@ class my_models
2933MY_MODELS_TPL ;
3034
3135$ filename = dirname (dirname (__FILE__ )) . '/my_models.php ' ;
32- file_put_contents ($ filename , $ my_models_tpl );
36+ file_put_contents ($ filename , $ my_models_tpl );
37+
38+ function work ($ file , &$ my_models )
39+ {
40+ if (is_dir ($ file )) {
41+ $ list = scandir ($ file );
42+ foreach ($ list as $ item ) {
43+ if ($ item == '. ' ) continue ;
44+ if ($ item == '.. ' ) continue ;
45+ $ item = $ file . '/ ' . $ item ;
46+ if (is_dir ($ item )) { // 目录,继续向下遍历
47+ work ($ item , $ my_models );
48+ } else { // 文件,则判断是否PHP,cd
49+
50+ if (pathinfo ($ item , PATHINFO_EXTENSION ) == 'php ' ) {
51+ $ model_name = get_model_name ($ item );
52+ $ my_models .= " * @property $ model_name $ model_name \n" ;
53+ }
54+ }
55+ }
56+ } else {
57+ echo "not dir!! " ;
58+ }
59+ }
60+
61+ echo $ my_models ;
62+
63+ function get_model_name ($ file )
64+ {
65+ $ file = basename ($ file );
66+ $ file = str_replace ('.php ' , '' , $ file );
67+ return $ file ;
68+ }
0 commit comments