1.https://github.com/topdown/phpStorm-CC-Helpers
2.External Libraries上右鍵->Configure PHP Include Path
3.system/core Controller.php Model.php database/DB_query_builder.php 選中3個核心文件->右鍵->Mark as Plain Text
4.新建 application/controllers/test/Cli.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Cli extends CI_Controller {
function filename($path=APPPATH . 'models/', $exten = '.php', $ifchild = true){
static $file_array=array();
$path = preg_replace('/(.*)([^\/])$/', '$1$2/', $path);
if (is_dir($path)) {
$H = @ opendir($path);
while(false !== ($_file=readdir($H))){
if(is_dir($path.$_file) && $_file != "." && $_file!=".."){
if($ifchild){
$this->filename($path.$_file, $exten ,$ifchild);
}
}elseif(is_file($path.$_file) && $_file!="." && $_file!=".."){
if($exten == '*'){
array_push($file_array, $_file);
} else {
if(preg_match('/(.*)'.$exten.'/', '/'.$_file.'/')){
array_push($file_array, $_file);
}
}
}
}
closedir($H);
}
$array = $file_array;
return $array;
}
function create_my_models(){
$content_header = <<< 'str'
<?php die();
/**
* Add you custom models here that you are loading in your controllers
*
* <code>
* $this->site_model->get_records()
* </code>
* Where site_model is the model Class
*
* ---------------------- Models to Load ----------------------
* <examples>
*
str;
$content_ender = <<< 'str'
*/
class my_models
{
}
// End my_models.php
str;
$my_modes_full_path = './my_models.php';
if(!file_exists($my_modes_full_path)){
if($fp=fopen($my_modes_full_path,'w')){
fwrite($fp,$content_header);
} else {
echo '創建文件失敗, 請檢查是否爲權限不足!' . PHP_EOL;
exit();
}
} else {
echo '文件已存在!' . PHP_EOL;
exit();
}
$model_path = APPPATH . 'models/';
$library_path = APPPATH . 'libraries/';
$model_filenames = $this->filename($model_path);
$library_filenames = $this->filename($library_path);
// 去重(也可以不操作去重,不過生成的文件會有紅線)
$filenames = array_merge($model_filenames, $library_filenames);
$filenames = array_flip($filenames);
$filenames = array_keys($filenames);
$line = '';
foreach ($filenames as $filename) {
$filename = str_replace(strrchr($filename, "."),"",$filename);
$line .= '* @property ' . $filename .' $'. $filename . "\r\n";
}
fwrite($fp,$line);
fwrite($fp,$content_ender);
fclose($fp);
}
}
5.項目根目錄 php index.php test/cli create_my_models