phpstorm配置ci框架代码提示

教程地址及说明

https://github.com/topdown/phpStorm-CC-Helpers

my_models文件生成工具

  • 新建 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);
    }

}
  • 运行 cli
sudo -u www php index.php test/cli create_my_models
  • my_models 文件生成在 index.php同目录下, 替换掉原my_models.php文件即可

注意⚠️

有些model或者library调用时使用的变量可能会有大小写区分,做如下修改

比如: my_models.php 中

/**
* @property Elasticsearch_client $Elasticsearch_client
*/

实际调用的时候使用的是:
$es_result = $this->elasticsearch_client->search('tip', 'tip', $params);

则修改 my_models.php 中对应变量行如下:
/**
* @property Elasticsearch_client $elasticsearch_client
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值