0

This code works...

$season_view_builder =  new Hockey_season_view_builder($season_id);

However, if I use the following code I get the white screen of death.

$builder = 'Hockey_season_view_builder';
$season_view_builder =  new $builder($season_id);

Can CodeIgniter create new class instances from a variable name? Is there some kind of weird codeigniter syntax to this?

I really need to generate and return new classes dynamically to make my factory pattern work.

Thanks for any help! I'll keep trying different approaches and post if I find anything.

TracyH
  • 11
  • 4
  • What does this have to do with codeigniter? Ci3 classes are loaded via the `load` method not by requiring and issuing a `new` – Alex Jan 14 '18 at 22:48

1 Answers1

0

I was looking at another post and saw the correct answer which had to do with using namespaces. I've kind of hacked my CodeIgniter to use namespaces so I needed to do

$builder = 'Hockey_season_view_builder';
$var = __NAMESPACE__ . '\\' . $builder;
$season_view_builder =  new $var($season_id);

Thank you and sorry about the foolish question.

TracyH
  • 11
  • 4
  • If you really need namespaces use a more modern framework like laravel or symphony. Ci4 is in development and will support namespaces, and all the modern stuff but isn't ready yet. Ci3 seems an odd choice. – Alex Jan 14 '18 at 22:50