Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Yii know CWebApplication exists?

I was trying to unravel a little bit how Yii initializes for my own educational purposes. But I got stuck very much at the beginning. So here it goes:

I understand how in index.php two files are being assigned to a variable:

$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/../protected/config/main.php';

I understand how the first file gets included by including the variable $yii:

require_once($yii);

I understand that a call is made to a static method in the empty class Yii{} (found in yii.php) which is an extension of the class Yiibase{} (found in Yiibase.php) and that the variable $config is passed to that that method:

Yii::createWebApplication($config)->run();

What I don't understand is:

  • what ->run() does and where it comes from?
  • How in the method createWebApplication an object (CWebApplication) is created that I don't see included in a file up until that point. How does it know the class CWebApplication{} exists?

1 Answers

createWebApplication() # just returns new CWebApplication($config) # which has the run() # method and this class can be easily autoimported by an earlier registration of an autoloder #.

like image 134
o_nix Avatar answered Jan 06 '26 10:01

o_nix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!