Yii Framework Forum: Yii project blueprints - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Yii project blueprints

#1 User is offline   najaram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-May 15
  • Location:Philippines

Posted 08 June 2015 - 07:40 AM

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.
0

#2 User is offline   najaram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-May 15
  • Location:Philippines

Posted 13 June 2015 - 10:31 AM

I have found the solution for my question http://stackoverflow...autoload-models
I just need to define the paths in import section of the config/console. :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users