Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct class namespacing in the user guide #1402

Merged
merged 2 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions user_guide_src/source/cli/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Let's create a simple controller so you can see it in action. Using your
text editor, create a file called Tools.php, and put the following code
in it::

<?php
class Tools extends \CodeIgniter\Controller {
<?php namespace CodeIgniter;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class Tools extends Controller {

public function message($to = 'World')
{
Expand Down
24 changes: 19 additions & 5 deletions user_guide_src/source/extending/core_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ the core system class, you would create your class like this::

namespace App\Libraries;

class RouteCollection implements \CodeIgniter\Router\RouteCollectionInterface
use CodeIgniter\Router\RouteCollectionInterface;

class RouteCollection implements RouteCollectionInterface
{

}
Expand Down Expand Up @@ -78,14 +80,22 @@ identical to replacing a class with a one exception:

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

class RouteCollection extends \CodeIgniter\Router\RouteCollection
namespace App\Libraries;

use CodeIgniter\Router\RouteCollection;

class RouteCollection extends RouteCollection
{

}

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

class RouteCollection implements \CodeIgniter\Router\RouteCollection
namespace App\Libraries;

use CodeIgniter\Router\RouteCollection;

class RouteCollection implements RouteCollection
jim-parry marked this conversation as resolved.
Show resolved Hide resolved
{
public function __construct()
{
Expand All @@ -99,7 +109,11 @@ instead of the native ones (this is known as “method overriding”). This allo
If you are extending the Controller core class, then be sure to extend your new class in your application controller’s
constructors::

class Home extends App\BaseController {
namespace App\Controllers;

}
use App\BaseController;

class Home extends BaseController {

}

9 changes: 6 additions & 3 deletions user_guide_src/source/general/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ If you need to create a new configuration file you would create a new file at yo
**/application/Config** by default. Then create the class and fill it with public properties that
represent your settings::

<?php namespace Config;
namespace Config;

use CodeIgniter\Config\BaseConfig ;

class App extends \CodeIgniter\Config\BaseConfig
class App extends BaseConfig
{
public $siteName = 'My Great Site';
public $siteEmail = '[email protected]';
Expand Down Expand Up @@ -200,7 +202,8 @@ A sample configuration class setup for this::

namespace App\Config;

class MySalesConfig extends \CodeIgniter\Config\BaseConfig
use CodeIgniter\Config\BaseConfig
class MySalesConfig extends BaseConfig
jim-parry marked this conversation as resolved.
Show resolved Hide resolved
{
public $target = 100;
public $campaign = "Winter Wonderland";
Expand Down
28 changes: 20 additions & 8 deletions user_guide_src/source/incoming/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ Let's try it: Hello World!
Let's create a simple controller so you can see it in action. Using your text editor, create a file called Blog.php,
and put the following code in it::

<?php
class Blog extends \CodeIgniter\Controller
<?php namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class Blog extends Controller
{
public function index()
{
Expand All @@ -53,15 +55,19 @@ If you did it right, you should see::

This is valid::

<?php
class Blog extends \CodeIgniter\Controller {
<?php namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class Blog extends Controller {

}

This is **not** valid::

<?php
class blog extends \CodeIgniter\Controller {
<?php namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class blog extends Controller {

}

Expand All @@ -83,7 +89,10 @@ controller gets called.**
Let's try it. Add a new method to your controller::

<?php
class Blog extends \CodeIgniter\Controller {
<?php namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class Blog extends Controller {

public function index()
{
Expand Down Expand Up @@ -286,7 +295,10 @@ You can define an array of helper files as a class property. Whenever the contro
these helper files will be automatically loaded into memory so that you can use their methods anywhere
inside the controller::

class MyController extends \CodeIgniter\Controller
<?php namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class MyController extends Controller {
{
protected $helpers = ['url', 'form'];
}
Expand Down
5 changes: 4 additions & 1 deletion user_guide_src/source/incoming/incomingrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ Accessing the Request
An instance of the request class already populated for you if the current class is a descendant of
``CodeIgniter\Controller`` and can be accessed as a class property::

class UserController extends CodeIgniter\Controller
namespace App\Controllers;
user CodeIgniter\Controller;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class UserController extends Controller
{
public function index()
{
Expand Down
12 changes: 11 additions & 1 deletion user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ instance of the database connection and you're good to go.

::

namespace App\Models;
use \CodeIgniter\Database\ConnectionInterface;

class UserModel
Expand Down Expand Up @@ -46,7 +47,10 @@ Creating Your Model
To take advantage of CodeIgniter's model, you would simply create a new model class
that extends ``CodeIgniter\Model``::

class UserModel extends \CodeIgniter\Model
namespace App\Models;
user CodeIgniter\Model;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class UserModel extends Model
{

}
Expand All @@ -64,6 +68,9 @@ This ensures that within the model any references to ``$this->db`` are made thro
connection.
::

namespace App\Models;
user CodeIgniter\Model;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class UserModel extends \CodeIgniter\Model
jim-parry marked this conversation as resolved.
Show resolved Hide resolved
{
protected $DBGroup = 'group_name';
Expand All @@ -79,6 +86,9 @@ The model class has a few configuration options that can be set to allow the cla
to work seamlessly for you. The first two are used by all of the CRUD methods to determine
what table to use and how we can find the required records::

namespace App\Models;
user CodeIgniter\Model;
jim-parry marked this conversation as resolved.
Show resolved Hide resolved

class UserModel extends \CodeIgniter\Model
jim-parry marked this conversation as resolved.
Show resolved Hide resolved
{
protected $table = 'users';
Expand Down
6 changes: 5 additions & 1 deletion user_guide_src/source/testing/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The Helper Trait
You can use either of the base test classes, but you do need to use the ``ControllerTester`` trait
within your tests::

namespace CodeIgniter;

use Tests\Support\Helpers\ControllerTester;

class TestControllerA extends \CIDatabaseTestCase
Expand All @@ -28,9 +30,11 @@ the request body, URI, and more. You specify the controller to use with the ``co
fully qualified class name of your controller. Finally, call the ``execute()`` method with the name of the method
to run as the parameter::

namespace CodeIgniter;

use Tests\Support\Helpers\ControllerTester;

class TestControllerA extends CIDatabaseTestCase
class TestControllerA extends \CIDatabaseTestCase
{
use ControllerTester;

Expand Down
6 changes: 4 additions & 2 deletions user_guide_src/source/tutorial/create_news_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ fields in the ``$allowedFields`` property.

::

<?php
class NewsModel extends \CodeIgniter\Model
<?php namespace App\Models;
use CodeIgniter\Model;

class NewsModel extends Model
{
protected $table = 'news';

Expand Down
3 changes: 2 additions & 1 deletion user_guide_src/source/tutorial/news_section.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ your database properly as described :doc:`here <../database/configuration>`.
<?php

namespace App\Models;
use CodeIgniter\Model;

class NewsModel extends \CodeIgniter\Model
class NewsModel extends Model
{
protected $table = 'news';
}
Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ code.
::

<?php namespace App\Controllers;
class Pages extends CodeIgniter\Controller {
use CodeIgniter\Controller;

class Pages extends Controller {

public function view($page = 'home')
{
Expand Down