Hello Guys,
I’m reading the Yii Project Blueprints book. I’m on chapter 2 Discovering What’s Nearby.
on the part where I created a class under commands folder, here is the code:
class ImportLocationsCommand extends CConsoleCommand
{
public function actionImportLocations()
{
echo "Loading Data...\n";
$data = $this->getData();
echo "Truncating old data...\n";
Location::model()->deleteAll();
echo "Importing Data...\n";
foreach($data as $id=>$content)
{
$model = new Location;
$model->attributes = $content;
$model->save();
}
}
private function getData()
{
$file = __DIR__ . '/../data/parks.json';
return CJSON::decode(file_get_contents($file));
}
}
I also have a json file under the data folder.
I’ve run this through the terminal
"php yiic importlocations importlocations". But then I get this result:
Loading Data...
Truncating old data...
PHP Error[2]: include(Location.php): failed to open stream: No such file or directory
in file /var/www/html/yii/framework/YiiBase.php at line 432
#0 /var/www/html/yii/framework/YiiBase.php(432): autoload()
#1 unknown(0): autoload()
#2 /var/www/html/nearby/protected/commands/ImportLocationsCommand.php(12): spl_autoload_call()
#3 unknown(0): ImportLocationsCommand->actionImportLocations()
#4 /var/www/html/yii/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs()
#5 /var/www/html/yii/framework/console/CConsoleCommandRunner.php(71): ImportLocationsCommand->run()
#6 /var/www/html/yii/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run()
#7 /var/www/html/yii/framework/base/CApplication.php(184): CConsoleApplication->processRequest()
#8 /var/www/html/yii/framework/yiic.php(33): CConsoleApplication->run()
#9 /var/www/html/nearby/protected/yiic.php(7): require_once()
#10 /var/www/html/nearby/protected/yiic(4): require_once()
I understand that it cannot find the Location.php but i’m not sure how to include it or what configuration I need to do.
Hope you can help me guys.
Thanks in advance.