Skip to content

Commit 5a29fcd

Browse files
authored
Merge pull request #4022 from totoprayogo1916/use-short-tag
Update examples
2 parents e730077 + 9c8652e commit 5a29fcd

29 files changed

+247
-147
lines changed

user_guide_src/source/cli/cli.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ Let's create a simple controller so you can see it in action. Using your
3838
text editor, create a file called Tools.php, and put the following code
3939
in it::
4040

41-
<?php namespace App\Controllers;
41+
<?php
42+
43+
namespace App\Controllers;
4244

4345
use CodeIgniter\Controller;
4446

4547
class Tools extends Controller
4648
{
4749
public function message($to = 'World')
4850
{
49-
echo "Hello {$to}!".PHP_EOL;
51+
echo "Hello {$to}!" . PHP_EOL;
5052
}
5153
}
5254

user_guide_src/source/cli/cli_commands.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ Let's step through an example command whose only function is to report basic inf
9999
itself, for demonstration purposes. Start by creating a new file at **/app/Commands/AppInfo.php**. It
100100
should contain the following code::
101101

102-
<?php namespace App\Commands;
102+
<?php
103+
104+
namespace App\Commands;
103105

104106
use CodeIgniter\CLI\BaseCommand;
105107
use CodeIgniter\CLI\CLI;
@@ -112,7 +114,7 @@ should contain the following code::
112114

113115
public function run(array $params)
114116
{
115-
117+
// ...
116118
}
117119
}
118120

user_guide_src/source/cli/cli_library.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ Initializing the Class
2020
You do not need to create an instance of the CLI library, since all of it's methods are static. Instead, you simply
2121
need to ensure your controller can locate it via a ``use`` statement above your class::
2222

23-
<?php namespace App\Controllers;
23+
<?php
24+
25+
namespace App\Controllers;
2426

2527
use CodeIgniter\CLI\CLI;
2628

2729
class MyController extends \CodeIgniter\Controller
2830
{
29-
. . .
31+
// ...
3032
}
3133

3234
The class is automatically initialized when the file is loaded the first time.

user_guide_src/source/concepts/autoloader.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ by not hitting the file-system with extra ``is_file()`` calls. You can use the c
7171
third-party libraries that are not namespaced::
7272

7373
$classmap = [
74-
'Markdown' => APPPATH .'third_party/markdown.php'
74+
'Markdown' => APPPATH . 'third_party/markdown.php'
7575
];
7676

7777
The key of each row is the name of the class that you want to locate. The value is the path to locate it at.
@@ -89,7 +89,7 @@ Composer Support
8989
================
9090

9191
Composer support is automatically initialized by default. By default, it looks for Composer's autoload file at
92-
``ROOTPATH.'vendor/autoload.php'``. If you need to change the location of that file for any reason, you can modify
92+
``ROOTPATH . 'vendor/autoload.php'``. If you need to change the location of that file for any reason, you can modify
9393
the value defined in ``Config\Constants.php``.
9494

9595
.. note:: If the same namespace is defined in both CodeIgniter and Composer, CodeIgniter's autoloader will be

user_guide_src/source/concepts/factories.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ you get back the instance as before::
3838
class SomeOtherClass
3939
{
4040
$widgets = Factories::models('WidgetModel');
41-
...
41+
// ...
4242
}
4343

4444
Factory Parameters
@@ -92,7 +92,9 @@ that supplies options as an array property that matches the name of the componen
9292
if you wanted to ensure that all Filters used by your app were valid framework instances,
9393
your **Factories.php** file might look like this::
9494

95-
<?php namespace Config;
95+
<?php
96+
97+
namespace Config;
9698

9799
use CodeIgniter\Config\Factory as BaseFactory;
98100
use CodeIgniter\Filters\FilterInterface;

user_guide_src/source/concepts/services.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ always return the same instance::
5454

5555
If the creation method requires additional parameters, they can be passed after the service name::
5656

57-
$renderer = service('renderer', APPPATH.'views/');
57+
$renderer = service('renderer', APPPATH . 'views/');
5858

5959
The second function, ``single_service()`` works just like ``service()`` but returns a new instance of
6060
the class::
@@ -147,15 +147,17 @@ Imagine that you've created a new directory, ``Blog`` in your root directory. Th
147147
models, etc, and you'd like to make some of the classes available as a service. The first step is to create a new file:
148148
``Blog\Config\Services.php``. The skeleton of the file should be::
149149

150-
<?php namespace Blog\Config;
150+
<?php
151+
152+
namespace Blog\Config;
151153

152154
use CodeIgniter\Config\BaseService;
153155

154156
class Services extends BaseService
155157
{
156158
public static function postManager()
157159
{
158-
...
160+
// ...
159161
}
160162
}
161163

user_guide_src/source/dbmgmt/migration.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ migrations go in the **app/Database/Migrations/** directory and have names such
4747
as *20121031100537_add_blog.php*.
4848
::
4949

50-
<?php namespace App\Database\Migrations;
50+
<?php
51+
52+
namespace App\Database\Migrations;
5153

5254
use CodeIgniter\Database\Migration;
5355

5456
class AddBlog extends Migration
5557
{
56-
5758
public function up()
5859
{
5960
$this->forge->addField([
@@ -64,12 +65,12 @@ as *20121031100537_add_blog.php*.
6465
'auto_increment' => true,
6566
],
6667
'blog_title' => [
67-
'type' => 'VARCHAR',
68-
'constraint' => '100',
68+
'type' => 'VARCHAR',
69+
'constraint' => '100',
6970
],
7071
'blog_description' => [
71-
'type' => 'TEXT',
72-
'null' => true,
72+
'type' => 'TEXT',
73+
'null' => true,
7374
],
7475
]);
7576
$this->forge->addKey('blog_id', true);
@@ -117,17 +118,25 @@ another database is used for mission critical data. You can ensure that migratio
117118
against the proper group by setting the ``$DBGroup`` property on your migration. This name must
118119
match the name of the database group exactly::
119120

120-
<?php namespace App\Database\Migrations;
121+
<?php
122+
123+
namespace App\Database\Migrations;
121124

122125
use CodeIgniter\Database\Migration;
123126

124127
class AddBlog extends Migration
125128
{
126129
protected $DBGroup = 'alternate_db_group';
127130

128-
public function up() { . . . }
131+
public function up()
132+
{
133+
// ...
134+
}
129135

130-
public function down() { . . . }
136+
public function down()
137+
{
138+
// ...
139+
}
131140
}
132141

133142
Namespaces
@@ -159,11 +168,12 @@ Usage Example
159168
In this example some simple code is placed in **app/Controllers/Migrate.php**
160169
to update the schema::
161170

162-
<?php namespace App\Controllers;
171+
<?php
172+
173+
namespace App\Controllers;
163174

164175
class Migrate extends \CodeIgniter\Controller
165176
{
166-
167177
public function index()
168178
{
169179
$migrate = \Config\Services::migrations();
@@ -177,7 +187,6 @@ to update the schema::
177187
// Do something with the error here...
178188
}
179189
}
180-
181190
}
182191

183192
*******************

user_guide_src/source/extending/basecontroller.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ CodeIgniter's core Controller should not be changed, but a default class extensi
66
**app/Controllers/BaseController.php**. Any new controllers you make should extend ``BaseController`` to take
77
advantage of preloaded components and any additional functionality you provide::
88

9-
<?php namespace App\Controllers;
10-
9+
<?php
10+
11+
namespace App\Controllers;
12+
1113
use CodeIgniter\Controller;
12-
13-
class Home extends BaseController {
14-
14+
15+
class Home extends BaseController
16+
{
17+
// ...
1518
}
1619

1720
Preloading Components

user_guide_src/source/extending/core_classes.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ can find your class, that your new class extends the appropriate interface, and
4949
For example, if you have a new ``App\Libraries\RouteCollection`` class that you would like to use in place of
5050
the core system class, you would create your class like this::
5151

52-
<?php namespace App\Libraries;
52+
<?php
53+
54+
namespace App\Libraries;
5355

5456
use CodeIgniter\Router\RouteCollectionInterface;
5557

5658
class RouteCollection implements RouteCollectionInterface
5759
{
58-
60+
// ...
5961
}
6062

6163
Then you would modify the ``routes`` service to load your class instead::
@@ -81,28 +83,32 @@ identical to replacing a class with one exception:
8183

8284
For example, to extend the native RouteCollection class, you would declare your class with::
8385

84-
<?php namespace App\Libraries;
86+
<?php
87+
88+
namespace App\Libraries;
8589

8690
use CodeIgniter\Router\RouteCollection;
8791

8892
class RouteCollection extends RouteCollection
8993
{
90-
94+
// ...
9195
}
9296

9397
If you need to use a constructor in your class make sure you extend the parent constructor::
9498

95-
<?php namespace App\Libraries;
99+
<?php
100+
101+
namespace App\Libraries;
96102

97103
use CodeIgniter\Router\RouteCollection as BaseRouteCollection;
98104

99105
class RouteCollection extends BaseRouteCollection
100106
{
101-
public function __construct()
102-
{
103-
parent::__construct();
104-
}
105-
}
107+
public function __construct()
108+
{
109+
parent::__construct();
110+
}
111+
}
106112

107113
**Tip:** Any functions in your class that are named identically to the methods in the parent class will be used
108114
instead of the native ones (this is known as “method overriding”). This allows you to substantially alter the CodeIgniter core.

user_guide_src/source/general/configuration.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ The class should use the appropriate namespace, and it should extend
6464

6565
Define the class and fill it with public properties that represent your settings.::
6666

67-
<?php namespace Config;
67+
<?php
68+
69+
namespace Config;
6870

6971
use CodeIgniter\Config\BaseConfig;
7072

7173
class CustomClass extends BaseConfig
7274
{
73-
public $siteName = 'My Great Site';
74-
public $siteEmail = 'webmaster@example.com';
75+
public $siteName = 'My Great Site';
76+
public $siteEmail = 'webmaster@example.com';
7577

7678
}
7779

@@ -248,7 +250,9 @@ the method named for the configuration class and incorporate any returned proper
248250

249251
A sample configuration class setup for this::
250252

251-
<?php namespace App\Config;
253+
<?php
254+
255+
namespace App\Config;
252256

253257
use CodeIgniter\Config\BaseConfig;
254258

@@ -257,19 +261,24 @@ A sample configuration class setup for this::
257261
public $target = 100;
258262
public $campaign = "Winter Wonderland";
259263
public static $registrars = [
260-
'\App\Models\RegionalSales';
264+
'\App\Models\RegionalSales'
261265
];
262266
}
263267

264268
... and the associated regional sales model might look like::
265269

266-
<?php namespace App\Models;
270+
<?php
271+
272+
namespace App\Models;
267273

268274
class RegionalSales
269275
{
270276
public static function MySalesConfig()
271277
{
272-
return ['target' => 45, 'actual' => 72];
278+
return [
279+
'target' => 45,
280+
'actual' => 72,
281+
];
273282
}
274283
}
275284

0 commit comments

Comments
 (0)