use \Model_Name; // class names are ucfirst() ! use \Model\Name; // namespaces require backslashes !
Many thanks for taking the time to reply, your solution was very useful.. Further testing has shown these results where it is not essential to extend the Model Class. I am still undecided the best method to adopt but it is always good to have a choice.Harro Verton wrote on Tuesday 26th of June 2012:An application model class like app/classes/model/name.php either lives in the global namespace and is called "Model_name", or lives in the "\Model" namespace and is called "name". You either access it using \Model_Name (case one) or \Model\Name (case two). So it'suse \Model_Name; // class names are ucfirst() ! use \Model\Name; // namespaces require backslashes !
<?php
//================================
class Controller_Lifts extends Controller
{ //====================================
public function action_index( $data=array() )
{
# GOOD
# ESSENTIAL if not extending Model
require_once( APPPATH .'classes/model/cqq.php');
Cqq :: testing_123(); # GOOD
# LOADED AUTOMATICALLY - DOES NOT REQUIRE a "use" or require statement
\ Model_Cqq :: testing_123();
# ALSO GOOD \Model_Cqq :: testing_123();
# ALSO GOOD Model_Cqq :: testing_123(); # BAD \ Model \ Cqq :: testing_123();
# Fatal error: Cannot redeclare class Model_Cqq
# in E:\xamp-lite\...\authors\classes\model\cqq.php
# on line 321
die;
<?php
//===========================
class Cqq
{ //===========================
public static function testing_123()
{
$a=array
(
'__FILE__' => __FILE__,
'__CLASS__' => __CLASS__,
'__METHOD__' => __METHOD__,
'__NAMESPACE__' => __NAMESPACE__,
'__FUNCTION__' => __FUNCTION__,
'__LINE__' => __LINE__,
);
echo '<dl margin: 1em 4.2em; border:solid 2px">';
foreach( $a as $key => $value):
$value = $value ? $value : 'Not declared ???'; echo '<dt><b>' .$key .'</b></dt>';
echo '<dd>' .$value .'</dd>';
endforeach;
echo '</dl>';
} }#endclass
//===========================
class Model_Cqq extends \Model
{ //===========================
public static function testing_123()
{
$a=array
(
'__FILE__' => __FILE__,
'__CLASS__' => __CLASS__,
'__METHOD__' => __METHOD__,
'__NAMESPACE__' => __NAMESPACE__,
'__FUNCTION__' => __FUNCTION__,
'__LINE__' => __LINE__,
);
echo '<dl margin: 1em 4.2em; border:solid 2px">';
foreach( $a as $key => $value):
$value = $value ? $value : 'Not declared ???'; echo '<dt><b>' .$key .'</b></dt>';
echo '<dd>' .$value .'</dd>';
endforeach;
echo '</dl>';
} #}#endclass
__FILE__
E:\xamp-lite\...\authors\classes\model\cqq.php
__CLASS__
Cqq
__METHOD__
Cqq::testing_123
__NAMESPACE__
Not declared ???
__FUNCTION__
testing_123
__LINE__
30 __FILE__
E:\xamp-lite\...\authors\classes\model\cqq.php
__CLASS__
Model_Cqq
__METHOD__
Model_Cqq::testing_123
__NAMESPACE__
Not declared ???
__FUNCTION__
testing_123
__LINE__
59
It looks like you're new here. If you want to get involved, click one of these buttons!