Welcome Guest, Not a member yet? Register   Sign In
get_class_name
#3

[eluser]Simon 24[/eluser]
Thanks for the reply, but I am a couple of steps further along. I'll try to clarify my problem with an example below.

When using the same code in CodeIgniter as in a test file I get different results. So maybe there is something in the CodeIgniter Controller I can work around.

Example with a plain test file, outside CodeIgniter:
Code:
class Crud {
public static function inhertited_call()
{
  print get_called_class();
  print __CLASS__;
}

public function forward()
{
  self::inhertited_call();
}
}

class Product extends Crud {
public function forwarded_call()
{
  self::forward();
}
}

class Pages {
function view()
{
  print "Product::forwarded_call();";
  print "<br />";
  Product::forwarded_call();
  print "<hr />";
  print "Product::inhertited_call();";
  print "<br />";
  Product::inhertited_call();
}
}

Pages::view();

Results are:
Code:
Product::forwarded_call();
ProductCrud
-------------------------------------------------
Product::inhertited_call();
ProductCrud

But when I try this code in CodeIgniter I get a different result:

Product model:
Code:
class Crud extends CI_Model {
public static function inhertited_call()
{
  print get_called_class();
  print __CLASS__;
}

public function forward()
{
  self::inhertited_call();
}
}

class Product extends Crud {
public function forwarded_call()
{
  self::forward();
}
}

Pages controller:
Code:
class Pages extends MY_Controller {
        public function test ()
{
  $this->load->model('Product');
  
  print "Product::forwarded_call();";
  print "<br />";
  Product::forwarded_call();
  print "<hr />";
  print "Product::inhertited_call();";
  print "<br />";
  Product::inhertited_call();
}
}

Then I get these results:
Code:
Product::forwarded_call();
PagesCrud
---------------------------------------------
Product::inhertited_call();
ProductCrud

So in the 'forwarded call' I get the classname of the controller instead of the model. How can I fix this?

Thanks!
Sander


Messages In This Thread
get_class_name - by El Forum - 07-23-2012, 03:43 AM
get_class_name - by El Forum - 07-23-2012, 06:20 AM
get_class_name - by El Forum - 07-23-2012, 06:54 AM
get_class_name - by El Forum - 07-23-2012, 07:02 AM
get_class_name - by El Forum - 07-23-2012, 07:05 AM
get_class_name - by El Forum - 07-23-2012, 07:42 AM
get_class_name - by El Forum - 07-23-2012, 10:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB