Skip to content

Commit

Permalink
Change class filenames to Ucfirst
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Jul 22, 2013
1 parent 2d536f8 commit 2029231
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public function index()
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
/* Location: ./application/controllers/Welcome.php */
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@
require_once BASEPATH.'core/CodeIgniter.php';

/* End of file index.php */
/* Location: ./index.php */
/* Location: ./index.php */
12 changes: 8 additions & 4 deletions system/core/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ function &get_instance()
// Load the local application controller
// Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php'))
$class = ucfirst($RTR->class);
if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

include(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php');
include(APPPATH.'controllers/'.$RTR->directory.$class.'.php');

// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
Expand All @@ -257,9 +258,8 @@ function &get_instance()
*
* None of the methods in the app controller or the
* loader class can be called via the URI, nor can
* controller functions that begin with an underscore.
* controller methods that begin with an underscore.
*/
$class = $RTR->class;
$method = $RTR->method;

if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
Expand All @@ -271,6 +271,8 @@ function &get_instance()
$method = 'index';
}

$class = ucfirst($class);

if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Expand Down Expand Up @@ -309,6 +311,8 @@ function &get_instance()
$method = 'index';
}

$class = ucfirst($class);

if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Expand Down
31 changes: 15 additions & 16 deletions system/core/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,33 +261,32 @@ public function model($model, $name = '', $db_conn = FALSE)
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}

$model = strtolower($model);

foreach ($this->_ci_model_paths as $mod_path)
if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
if ($db_conn === TRUE)
{
continue;
$db_conn = '';
}

if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ($db_conn === TRUE)
{
$db_conn = '';
}
$CI->load->database($db_conn, FALSE, TRUE);
}

$CI->load->database($db_conn, FALSE, TRUE);
}
if ( ! class_exists('CI_Model', FALSE))
{
load_class('Model', 'core');
}

$model = ucfirst(strtolower($model));

if ( ! class_exists('CI_Model', FALSE))
foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
load_class('Model', 'core');
continue;
}

require_once($mod_path.'models/'.$path.$model.'.php');

$model = ucfirst($model);
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;
Expand Down
8 changes: 3 additions & 5 deletions system/core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ protected function _validate_request($segments)
return $segments;
}

$test = ($this->translate_uri_dashes === TRUE)
? str_replace('-', '_', $segments[0]) : $segments[0];
$test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);

// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$test.'.php'))
Expand All @@ -286,8 +285,7 @@ protected function _validate_request($segments)
$this->set_directory(array_shift($segments));
if (count($segments) > 0)
{
$test = ($this->translate_uri_dashes === TRUE)
? str_replace('-', '_', $segments[0]) : $segments[0];
$test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);

// Does the requested controller exist in the sub-directory?
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php'))
Expand All @@ -307,7 +305,7 @@ protected function _validate_request($segments)
{
// Is the method being specified in the route?
$segments = explode('/', $this->default_controller);
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php'))
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($segments[0]).'.php'))
{
$this->directory = '';
}
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/general/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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 tools.php, and put the following code
text editor, create a file called Tools.php, and put the following code
in it::

<?php
Expand Down
10 changes: 6 additions & 4 deletions user_guide_src/source/general/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Consider this URI::
example.com/index.php/blog/

In the above example, CodeIgniter would attempt to find a controller
named blog.php and load it.
named Blog.php and load it.

**When a controller's name matches the first segment of a URI, it will
be loaded.**
Expand All @@ -27,7 +27,7 @@ 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
text editor, create a file called Blog.php, and put the following code
in it::

<?php
Expand All @@ -41,6 +41,8 @@ in it::

Then save the file to your *application/controllers/* directory.

.. important:: The file must be called 'Blog.php', with a capital 'B'.

Now visit the your site using a URL similar to this::

example.com/index.php/blog/
Expand Down Expand Up @@ -136,7 +138,7 @@ present, as will be the case when only your site root URL is requested.
To specify a default controller, open your **application/config/routes.php**
file and set this variable::

$route['default_controller'] = 'blog';
$route['default_controller'] = 'Blog';

Where Blog is the name of the controller class you want used. If you now
load your main index.php file without specifying any URI segments you'll
Expand Down Expand Up @@ -272,7 +274,7 @@ and place your controller classes within them.
specify the folder. For example, let's say you have a controller located
here::

application/controllers/products/shoes.php
application/controllers/products/Shoes.php

To call the above controller your URI will look something like this::

Expand Down
7 changes: 4 additions & 3 deletions user_guide_src/source/general/creating_libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Naming Conventions
The Class File
==============

Classes should have this basic prototype (Note: We are using the name
Someclass purely as an example)::
Classes should have this basic prototype::

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Expand All @@ -56,6 +55,8 @@ Someclass purely as an example)::

/* End of file Someclass.php */

.. note:: We are using the name Someclass purely as an example.

Using Your Class
================

Expand All @@ -81,7 +82,7 @@ constructor::

$params = array('type' => 'large', 'color' => 'red');

$this->load->library('Someclass', $params);
$this->load->library('someclass', $params);

If you use this feature you must set up your class constructor to expect
data::
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/general/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Creating Your Own Libraries
===========================

Please read the section of the user guide that discusses how to
:doc:`create your own libraries <creating_libraries>`.
:doc:`create your own libraries <creating_libraries>`.
9 changes: 4 additions & 5 deletions user_guide_src/source/general/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ Where **Model_name** is the name of your class. Class names **must** have
the first letter capitalized with the rest of the name lowercase. Make
sure your class extends the base Model class.

The file name will be a lower case version of your class name. For
example, if your class is this::
The file name must match the class name. For example, if this is your class::

class User_model extends CI_Model {

Expand All @@ -98,7 +97,7 @@ example, if your class is this::

Your file will be this::

application/models/user_model.php
application/models/User_model.php

Loading a Model
===============
Expand All @@ -111,7 +110,7 @@ the following method::

If your model is located in a sub-directory, include the relative path
from your models directory. For example, if you have a model located at
*application/models/blog/queries.php* you'll load it using::
*application/models/blog/Queries.php* you'll load it using::

$this->load->model('blog/queries');

Expand Down Expand Up @@ -181,4 +180,4 @@ database. The following options for connecting are available to you:
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;

$this->load->model('Model_name', '', $config);
$this->load->model('model_name', '', $config);
31 changes: 30 additions & 1 deletion user_guide_src/source/general/styleguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,42 @@ identify a file as being complete and not truncated.

echo "Here's my code!";

/* End of file myfile.php */
/* End of file Myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */

.. note:: There should be no empty line or newline character(s) following
the closing comments. If you happen to see one when
submitting a pull request, please check your IDE settings and fix it.

File Naming
===========

Class files must be named in a Ucfirst-like manner, while any other file name
(configurations, views, generic scripts, etc.) should be in all lowercase.

**INCORRECT**::

somelibrary.php
someLibrary.php
SOMELIBRARY.php
Some_Library.php

This comment has been minimized.

Copy link
@pawelkg

pawelkg Jul 22, 2013

Contributor

Why Some_Library.php is in 'correct' and 'incorrect' examples?

This comment has been minimized.

Copy link
@narfbg

narfbg Jul 22, 2013

Author Contributor

Good point.
e3e2c69


Application_config.php
Application_Config.php
applicationConfig.php

**CORRECT**::

SomeLibrary.php
Some_Library.php

applicationconfig.php
application_config.php

Furthermore, class file names should match the name of the class itself.
For example, if you have a class named `Myclass`, then its filename must
be **Myclass.php**.

Class and Method Naming
=======================

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/general/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Where name is the name of your view file.
.. note:: The .php file extension does not need to be specified
unless you use something other than .php.

Now, open the controller file you made earlier called blog.php, and
Now, open the controller file you made earlier called Blog.php, and
replace the echo statement with the view loading method::

<?php
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/helpers/smiley_helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ View as described.
The Controller
--------------

In your `application/controllers/` folder, create a file called
In your **application/controllers/** directory, create a file called
smileys.php and place the code below in it.

.. important:: Change the URL in the :php:func:`get_clickable_smileys()`
Expand All @@ -70,7 +70,7 @@ the :doc:`Table Class <../libraries/table>`::

}

In your `application/views/` folder, create a file called `smiley_view.php`
In your **application/views/** folder, create a file called **smiley_view.php**
and place this code in it::

<html>
Expand Down
Loading

3 comments on commit 2029231

@TheDigitalOrchard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change made? Can you point me to a discussion about it? Thanks.

@goFrendiAsgard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@narfbg : I have the same question as @TheDigitalOrchard, is there any reason behind this?

@narfbg
Copy link
Contributor Author

@narfbg narfbg commented on 2029231 Nov 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read/comment here: #1805

Please sign in to comment.