I have upload my YII2 project to ubuntu 16.04. My source is no problem when run on localhost on my computer, but when I run it on the server ubuntu 16.04 with network, it has a problem. The model source can't find another relation model
public function getLokasiAwal()
{
return $this->hasOne(KotaBandara::className(), ['id_kota' => 'lokasi_awal']);
}
and i have error
Class 'backend\models\TypeNonstaf' not found
I have found the solution, I added the following code:
use backend\models\Kotabandara;
On top in model file but, in my source in localhost, I do not need to add that code
Can someone explain that issue??
As @rob006 pointed out, it appears that you had been working/running your app on a Windows local file system, which is case-preserving, but not case-sensitive.
When you first call upon a namespaced class directly or via the
useoperator, it passes this full class name as$classNameintoyii\BaseYii\autoload::($className)(Yii2's global class autoloading handler), which in turn attempts toincludethe corresponding class file, if found.So, on your Windows local machine, when you use
backend\models\KotaBandara, it will find and include any file associated with the corresponding path alias in a case-insensitive manner, thus it will find any of:@backend/models/KotaBandara.php@backend/models/Kotabandara.php@backend/models/kotabandara.php@backend/models/KoTaBaNdArA.phpThere can be only 1 target file with this sequence of paths/characters anyway.
However, when you migrate this code to a Ubuntu system, which is both case-preserving and case-sensitive, there is a distinct difference between
KotaBandara.phpandkotabandara.phpand in fact both files can exist side by side, unlike on Windows.So, you have to be precise here - on Ubuntu,
use backend\models\KotaBandarawill trigger the autoloader to find only the file whose path AND case matches, i.e.KotaBandara.php. If you named the filekotabandara.php, it will be found on Windows, but not on Ubuntu!