-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_model
More file actions
63 lines (45 loc) · 1.12 KB
/
create_model
File metadata and controls
63 lines (45 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
//parent directories
define('DS',DIRECTORY_SEPARATOR);
define('ROOT_PATH',dirname(__FILE__).DS);
define('APP',ROOT_PATH.'app'.DS);
define('PUBLIC_PATH',ROOT_PATH.'public'.DS);
require_once 'app/config/config_constants.php';
require_once 'vendor/autoload.php';
if(php_sapi_name() =='cli')
{
if(isset($argv[1]))
{
$model = $argv[1];
clearstatcache();
if(!file_exists(MODELS.$model.'.php'))
{
file_put_contents(MODELS.$model.'.php',getModelString($model));
die('Model created '.$model.' successfully');
}
else
{
die("$model already craeted before");
}
}
else
{
die('no data input found');
}
}
else
{
die('');
}
function getModelString($model)
{
$string ='<?php
namespace App\Models;
use App\Core\Model;
class '.$model.' extends Model
{
//you have to set table attributes her $id,$column_2,$column_3 ...
//you should set table name attribute or we can predict it like User to be users ,UserCategory user_categories
}';
return $string;
}