-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathgenerate.html
More file actions
909 lines (693 loc) · 27.5 KB
/
generate.html
File metadata and controls
909 lines (693 loc) · 27.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../../assets/css/combined.css">
<link rel="shortcut icon" href="./../../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../../';
</script>
<script src="./../../assets/js/combined.js"></script>
<title>Generate - Oil Package - FuelPHP Documentation</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<strong>FuelPHP, a PHP 5.3 Framework</strong>
Documentation
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="search" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">table of contents</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<section>
<h2 id="generate">Generate</h2>
<p>
Code Generation can be used to speed up development times by building much of the repetitive code for you. This
is entirely optionally - like all of oil - and all code can be edited however you like afterwards. You can generate the following items:
</p>
<ul>
<li><a href="#controllers">Controllers</a></li>
<li><a href="#models">Models</a></li>
<li><a href="#viewmodels">Viewmodels</a></li>
<li><a href="#migrations">Migrations</a></li>
<li><a href="#scaffolding">Scaffolding</a></li>
<li><a href="#admin">Admin scaffolding</a></li>
<li><a href="#tasks">Tasks</a></li>
<li><a href="#configs">Configs</a></li>
<li><a href="#packages">Packages</a></li>
<li><a href="#modules">Modules</a></li>
</ul>
<h3 id="controllers">Controllers</h3>
<p>
To generate a skeleton <a href="../../general/controllers/base.html">Controller</a> with actions and views
predefined, use the following command:
</p>
<pre class="cli"><code>$ php oil g controller posts action1 action2 action3
Created view: APPPATH/views/posts/action1.php
Created view: APPPATH/views/posts/action2.php
Created view: APPPATH/views/posts/action3.php
Created controller: APPPATH/classes/controller/posts.php</code></pre>
<p>This will produce a controller that looks like this:</p>
<pre class="php"><code>class Controller_Posts extends Controller_Template
{
public function action_action1()
{
$this->template->title = 'Posts » Action1';
$this->template->content = View::forge('posts/action1');
}
public function action_action2()
{
$this->template->title = 'Posts » Action2';
$this->template->content = View::forge('posts/action2');
}
public function action_action3()
{
$this->template->title = 'Posts » Action3';
$this->template->content = View::forge('posts/action3');
}
}
/* End of file posts.php */</code></pre>
<h3 id="models">Models</h3>
<p>
Generate a simple Model by listing fields and have
the <a href="../../general/migrations.html">Migration</a> automatically created for you to match:
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int
Created model: APPPATH/classes/model/post.php
Created migration: APPPATH/migrations/001_create_posts.php</code></pre>
<p>That will create a simple Model that uses <a href="../orm/intro.html">Orm</a>, so make sure the package is enabled in your config file. It will look like this:</p>
<pre class="php"><code>class Model_Post extends Orm\Model {
protected static $_properties = array(
'id',
'title',
'body',
'created_at',
'updated_at'
);
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => false,
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'mysql_timestamp' => false,
),
);
}
/* End of file post.php */
</code></pre>
<p>Not very exciting, but the migration is the useful part here:</p>
<pre class="php"><code>namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
'created_at' => array('type' => 'datetime'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}</code></pre>
<p>If you do not wish to generate a migration, simply supply the <code>--no-migration</code>:</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --no-migration
Created model: APPPATH/classes/model/post.php</code></pre>
<p>By default, the class name is generated singular (it represents one post), but the corresponding table is generated
in plural (in contains multiple posts). You can make the table use the same name as the model by using <code>--singular</code>.</p>
<h4>Generating Model using Model_Crud</h4>
<p>FuelPHP v1.1 added a simple Model_Crud base model which offers similar functionality of using ORM without overhead of relational data. You can have the model generated using this by adding <code>--crud</code></p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int created_at:datetime --crud
Created model: APPPATH/classes/model/post.php
Created migration: APPPATH/migrations/001_create_posts.php</code></pre>
<p>That will create a simple Model that uses Fuel\Core\Model_Crud. It will look like this:</p>
<pre class="php"><code>class Model_Post extends \Model_Crud
{
protected static $_properties = array(
'id',
'title',
'body',
'user_id',
'created_at',
'updated_at'
);
protected static $_table_name = 'posts';
}</code></pre>
<h4 id="no_timestamp">Generating Model Without Timestamp Option</h4>
<p>Add <code>--no-timestamp</code> to exclude the created/updated fields and observers.</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --no-timestamp</code></pre>
<pre class="php"><code>class Model_Post extends \Orm\Model
{
protected static $_properties = array(
'id',
'title',
'body',
'user_id'
);
}
</code></pre>
<pre class="php"><code>namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}
</code></pre>
<h4 id="timestamp_fields">Changing the Timestamp and Timestamp Fields</h4>
<p>
When you're using the timestamp fields in either ORM models or CRUD models (\Model_Crud) you can
chose your own field names. Use the <code>--created-at</code> and <code>--updated-at</code>
options to set your own field names.
</p>
<p>
By default, when you enable timestamps, the timestamps are stored in unixtime, as an integer. If you
prefer the MySQL DATETIME format, you can use the <code>--mysql-timestamp</code> option.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --mysql-timestamp --created-at=my_created</code></pre>
<p>Which will give you:</p>
<pre class="php"><code><?php
class Model_Post extends \Orm\Model
{
protected static $_properties = array(
'id',
'title',
'body',
'user_id',
'my_created',
'updated_at'
);
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => true,
'property' => 'my_created',
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'mysql_timestamp' => true,
),
);
}</code></pre>
<pre class="php"><code><?php
namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
'my_created' => array('constraint' => 11, 'type' => 'int'),
'updated_at' => array('constraint' => 11, 'type' => 'int'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}</code></pre>
<h4 id="model_soft">Generating Model using Model_Soft</h4>
<p>
FuelPHP v1.5 added a Model_Soft based ORM model. Add <code>--soft-delete</code> to use Model_Soft.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --soft-delete</code></pre>
<p>Which will give you:</p>
<pre class="php"><code><?php
class Model_Post extends \Orm\Model_Soft
{
protected static $_properties = array(
'id',
'title',
'body',
'user_id',
'created_at',
'updated_at',
'deleted_at',
);
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => false,
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_update'),
'mysql_timestamp' => false,
),
);
protected static $_soft_delete = array(
'mysql_timestamp' => false,
);
}
</code></pre>
<pre class="php"><code><?php
namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
'deleted_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}</code></pre>
<p>
If you wish changing deleted_at field name. Use the <code>--deleted-at</code> option to set your own field name.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --soft-delete --deleted-at=mydeleted</code></pre>
<h4 id="model_temporal">Generating Model using Model_Temporal</h4>
<p>
Add <code>--temporal</code> to use Model_Temporal.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --temporal</code></pre>
<p>Which will give you:</p>
<pre class="php"><code><?php
class Model_Post extends \Orm\Model_Temporal
{
protected static $_properties = array(
'id',
'temporal_start',
'temporal_end',
'title',
'body',
'user_id',
);
protected static $_temporal = array(
'mysql_timestamp' => false,
);
protected static $_primary_key = array('id', 'temporal_start', 'temporal_end');
protected static $_table_name = 'posts';
}
</code></pre>
<pre class="php"><code><?php
namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true),
'temporal_start' => array('constraint' => 11, 'type' => 'int'),
'temporal_end' => array('constraint' => 11, 'type' => 'int'),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}</code></pre>
<p class="note">Please note that <b>temporal_start</b> and <b>temporal_end</b> are not added to the migration's primary_key array. You have to add them manually.</p>
<p class="note"><code>--no-timestamp</code> is set to true by default which means both <b>created_at</b> and <b>updated_at</b> fields and the related observers are ommited. You can bypass this default with <code>--no-timestamp=0</code> to get them back.</p>
<p>
If you wish changing temporal_start or temporal_end field name. Use <code>--temporal-start</code> or <code>--temporal-end</code> option to set your own field name.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --temporal --temporal-start=mystart --temporal-end=myend</code></pre>
<h4 id="model_nestedset">Generating Model using Model_Nestedset</h4>
<p>
Add <code>--nestedset</code> to use Model_Nestedset.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --nestedset</code></pre>
<p>Which will give you:</p>
<pre class="php"><code><?php
class Model_Post extends \Orm\Model_Nestedset
{
protected static $_properties = array(
'id',
'left_id',
'right_id',
'title',
'body',
'user_id',
);
protected static $_table_name = 'posts';
}
</code></pre>
<pre class="php"><code><?php
namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true),
'left_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true),
'right_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}</code></pre>
<p class="note"><code>--no-timestamp</code> is set to true by default which means both <b>created_at</b> and <b>updated_at</b> fields and the related observers are ommited.You can bypass this default with <code>--no-timestamp=0</code> to get them back.</p>
<p>
If you wish changing title, tree_id, left_id, right_id field name. Use one of <code>--title</code>, <code>--tre-id</code>, <code>--left-id</code>, <code>--right-id</code> options to set your own field name.
</p>
<pre class="cli"><code>$ php oil g model post title:varchar[50] body:text user_id:int --nestedset --title=mytitle --tree-id=mytreeid --left-id=myleftid --right-id=myrightid</code></pre>
<h3 id="viewmodels">Viewmodels</h3>
<p>
Optionally you have have oil to generate a Viewmodel class to accompany the view.
</p>
<pre class="cli"><code>$ php oil g controller posts action1 action2 action3 --with-viewmodel</code></pre>
<h3 id="running_migrations">Running Migrations</h3>
<p>
The following commands illustrate how to use the refine command to run useful migration tasks,
assuming that the system is currently at migration 5. The migrate task can be given parameters to
move directly to a given version, or just up/down by a single version.
</p>
<pre class="cli"><code>$ php oil refine migrate
Currently on migration: 5.
$ php oil refine migrate --version=4
Migrated to version: 4.
$ php oil refine migrate --version=5
Migrated to version: 5.
$ php oil refine migrate:down
Migrated to version: 4.
$ php oil refine migrate:up
Migrated to version: 5.</code></pre>
<p class="note">The following field types are supported: <strong>string[n]</strong>, <strong>varchar[n]</strong>, <strong>int[n]</strong>, <strong>enum[value1, value2]</strong>, <strong>decimal[n, n]</strong>, <strong>float[n, n]</strong>, <strong>text</strong>, <strong>blob</strong>, <strong>datetime</strong>, <strong>date</strong>, <strong>timestamp</strong> and <strong>time</strong>.</p>
<h3 id="migrations">Generating Migrations</h3>
<p>
You can generate migrations without creating a model. This could be used to rename a table, or add fields to a table in a way that is easy to deploy in other environments.
</p>
<pre class="cli"><code>$ php oil generate migration rename_table_users_to_accounts
Building magic migration: rename_table
Created migration: APPPATH/migrations/002_rename_table_users_to_accounts.php</code></pre>
<h3 id="magic_migrations">Magic Migrations</h3>
<p>There are a number of "magic" migrations which automatically build you a migration based on a prefix to your migration name.</p>
<pre class="cli"><code>$ php oil generate migration create_users name:text email:string[50] password:string[125]
$ php oil generate migration rename_table_users_to_accounts
$ php oil generate migration add_bio_to_accounts bio:text
$ php oil generate migration delete_bio_from_accounts bio:text
$ php oil generate migration rename_field_name_to_username_in_accounts
$ php oil generate migration drop_accounts
</code></pre>
<p>Note: Be careful when naming your migrations that you don't begin with any keywords by accident.</p>
<h3 id="scaffolding">Scaffolding</h3>
<p>
Scaffolding is the really exciting part of Oil's code generation. This approach is heavily borrowed from Rails who have done
a great job with it. The idea is that you create not only the MVC skeletons and migrations, but populate them with default CRUD code
so the code will actually work after writing the command.
</p>
<p>
If you wish to generate in modules, simply supply <code>--module=<modulename></code> option.
</p>
<pre class="cli"><code>$ php oil g scaffold monkey name:string description:text
Created model: APPPATH/classes/model/monkey.php
Created migration: APPPATH/migrations/003_create_monkeys.php
Created controller: APPPATH/classes/controller/monkeys.php
Created view: APPPATH/views/monkeys/index.php
Created view: APPPATH/views/monkeys/view.php
Created view: APPPATH/views/monkeys/create.php
Created view: APPPATH/views/monkeys/edit.php
Created view: APPPATH/views/monkeys/_form.php
$ php oil refine migrate
Migrated to latest version: 3.
</code></pre>
<p>
As you can see lots of code is generated by this command including a command that is executed in the second command.
The controller looks like this:
</p>
<pre class="php"><code>class Controller_Monkey extends Controller_Template
{
public function action_index()
{
$data['monkeys'] = Model_Monkey::find('all');
$this->template->title = "Monkeys";
$this->template->content = View::forge('monkey/index', $data);
}
public function action_view($id = null)
{
$data['monkey'] = Model_Monkey::find($id);
$this->template->title = "Monkey";
$this->template->content = View::forge('monkey/view', $data);
}
public function action_create($id = null)
{
if (Input::method() == 'POST')
{
$monkey = Model_Monkey::forge(array(
'name' => Input::post('name'),
'description' => Input::post('description'),
));
if ($monkey and $monkey->save())
{
Session::set_flash('success', 'Added monkey #'.$monkey->id.'.');
Response::redirect('monkey');
}
else
{
Session::set_flash('error', 'Could not save monkey.');
}
}
$this->template->title = "Monkeys";
$this->template->content = View::forge('monkey/create');
}
public function action_edit($id = null)
{
$monkey = Model_Monkey::find($id);
if (Input::method() == 'POST')
{
$monkey->name = Input::post('name');
$monkey->description = Input::post('description');
if ($monkey->save())
{
Session::set_flash('success', 'Updated monkey #' . $id);
Response::redirect('monkey');
}
else
{
Session::set_flash('error', 'Could not update monkey #' . $id);
}
}
else
{
$this->template->set_global('monkey', $monkey, false);
}
$this->template->title = "Monkeys";
$this->template->content = View::forge('monkey/edit');
}
public function action_delete($id = null)
{
if ($monkey = Model_Monkey::find($id))
{
$monkey->delete();
Session::set_flash('success', 'Deleted monkey #'.$id);
}
else
{
Session::set_flash('error', 'Could not delete monkey #'.$id);
}
Response::redirect('monkey');
}
}</code></pre>
<h3 id="admin">Admin scaffolding</h3>
<p>
You can swap scaffold with admin and generate a controller which extends Controller_Admin instead of Controller_Template.
On the first use of this command an admin skeleton will be generated, to expand this skeleton use the skip force argument.
To generate in subdirectories name the prefix the model's name accordingly.
</p>
<p>
If you wish to generate in modules, simply supply <code>--module=<modulename></code> option.
</p>
<pre class="cli"><code>$ php oil g admin project_entry title:string abstract:text full_text:text project_id:int is_draft:int order:int -s
Creating migration: APPPATH/migrations/012_create_project_entries.php
Creating model: APPPATH/classes/model/project/entry.php
Creating controller: APPPATH/classes/controller/admin/project/entry.php
Creating view: APPPATH/views/admin/project/entry/index.php
Creating view: APPPATH/views/admin/project/entry/view.php
Creating view: APPPATH/views/admin/project/entry/create.php
Creating view: APPPATH/views/admin/project/entry/edit.php
Creating view: APPPATH/views/admin/project/entry/_form.php
</code></pre>
<h3 id="tasks">Tasks</h3>
<p>
You can also have oil generate the skeleton of a new task.
</p>
<pre class="cli"><code>$ php oil g task newtask cmd1 cmd2</code></pre>
<p>
Which will generate
</p>
<pre class="php"><code><?php
namespace Fuel\Tasks;
class Newtask
{
public static function run($args = NULL)
{
echo "\n===========================================";
echo "\nRunning DEFAULT task [Newtask:Run]";
echo "\n-------------------------------------------\n\n";
/***************************
Put in TASK DETAILS HERE
**************************/
}
public static function cmd1($args = NULL)
{
echo "\n===========================================";
echo "\nRunning task [Newtask:Cmd1]";
echo "\n-------------------------------------------\n\n";
/***************************
Put in TASK DETAILS HERE
**************************/
}
public static function cmd2($args = NULL)
{
echo "\n===========================================";
echo "\nRunning task [Newtask:Cmd2]";
echo "\n-------------------------------------------\n\n";
/***************************
Put in TASK DETAILS HERE
**************************/
}
}
/* End of file tasks/newtask.php */</code></pre>
<h3 id="configs">Configs</h3>
<p>
To generate a <a href="../../classes/config.html">Config</a>, use the following command:
</p>
<pre class="cli"><code>$ php oil g config sample hello:world
Created config: APPPATH/config/sample.php</code></pre>
<p>This will produce a config that looks like this:</p>
<pre class="php"><code>return array (
'hello' => 'world',
);
/* End of file sample.php */</code></pre>
<h3>Generate Config from COREPATH</h3>
<p>
To combine config from COREPATH/config if APPPATH/config doesn't have one
</p>
<pre class="cli"><code>$ php oil g config package
Created config: APPPATH/config/package.php</code></pre>
<p>This will produce a config that looks like this:</p>
<pre class="php"><code>return array (
'sources' =>
array (
0 => 'github.com/fuel-packages',
),
);</code></pre>
<h3>Force Update Config from COREPATH & APPPATH</h3>
<p>
To combine config from COREPATH/config and combine APPPATH/config to APPPATH/config
</p>
<pre class="cli"><code>$ php oil g config form --overwrite
Created config: APPPATH/config/form.php</code></pre>
<p>This will produce a config that looks like this:</p>
<pre class="php"><code>return array (
'prep_value' => true,
'auto_id' => true,
'auto_id_prefix' => '',
'form_method' => 'post',
);
/* End of file form.php */</code></pre>
<h3 id="packages">Packages</h3>
<p>
To generate a <a href="../../general/packages.html">Package</a>, use the following command:
</p>
<pre class="cli"><code>$ php oil g package sample
Creating file: PKGPATH/sample/classes/sample.php
Creating file: PKGPATH/sample/config/sample.php
Creating file: PKGPATH/sample/bootstrap.php</code></pre>
<p class="note">The path where the package is generated is PKGPATH by default, but this value can be changed to any path defined in the <code>package_paths</code> config by passing the <code>--path=package_path</code> or <code>-p=package_path</code> option to the command.</p>
<h3>Generate Driver-based Package</h3>
<p>If you wish to generate a driver-based package, simply supply the <code>--drivers</code> or <code>-d</code> option:</p>
<pre class="cli"><code>$ php oil g package sample -d
Creating file: PKGPATH/sample/classes/sample.php
Creating file: PKGPATH/sample/classes/sample/driver.php
Creating file: PKGPATH/sample/config/sample.php
Creating file: PKGPATH/sample/bootstrap.php</code></pre>
<p>You can also generate your own drivers. Simply pass the driver names separated by commas to the <code>--drivers</code> or <code>-d</code> option:</p>
<pre class="cli"><code>$ php oil g package sample -d=driver1,driver2
Creating file: PKGPATH/sample/classes/sample.php
Creating file: PKGPATH/sample/classes/sample/driver.php
Creating file: PKGPATH/sample/classes/sample/driver1.php
Creating file: PKGPATH/sample/classes/sample/driver2.php
Creating file: PKGPATH/sample/config/sample.php
Creating file: PKGPATH/sample/bootstrap.php</code></pre>
<h3>Generate Package with VCS files</h3>
<p>If you wish to generate composer.json and README.md files for your package, simply supply the <code>--vcs</code> or <code>-v</code> option:</p>
<pre class="cli"><code>$ php oil g package sample -v
Creating file: PKGPATH/sample/composer.json
Creating file: PKGPATH/sample/README.md
Creating file: PKGPATH/sample/classes/sample.php
Creating file: PKGPATH/sample/config/sample.php
Creating file: PKGPATH/sample/bootstrap.php</code></pre>
<h3 id="modules">Modules</h3>
<p>
To generate a <a href="../../general/modules.html">Module</a>, use the following command:
</p>
<pre class="cli"><code>$ php oil g module blog</code></pre>
<p>
This command will create a folder called <code>blog</code> in you app's module path defined in <code>config.module_paths</code>. If you have multiple module paths defined, you will get a list of paths that you can choose from, e.g.:
</p>
<pre class="cli"><code>$ php oil g module blog
Your app has multiple module paths defined. Please choose the appropriate path from the list below
[1] /var/www/fuel/shared/modules/
[2] /var/www/fuel/app/modules/</code></pre>
<p>
To provide for even easier module generation, you can supply the <code>--folders</code> option with a list of comma-separated folders to be created. These can be nested almost indefinitely and you don't need to provide every parent folder. A short yet useful example can be:
</p>
<pre class="cli"><code>$ php oil g module blog --folders=classes/model,classes/controller,config,lang</code></pre>
</section>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2014 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
</p>
</footer>
</div>
</body>
</html>