This is how i am trying to get some apartments name from the database, but i am always getting er error. This is how i am trying to get the apartments names
$userapt = $user->getApartments()->getIterator();
while ($userapt->valid()) {
echo ($userapt->key() . ' => ' . $userapt->current()) . "\n";
$userapt->next();
}
$useraptName = $user->getApartment()->getIterator();
while ($useraptName->valid()) {
($useraptName->key() . ' => ' . var_dump($useraptName->current()) . "\n");
$useraptName->next();
}
Running this, I get following error:
Catchable Fatal Error: Object of class MyBundle\Entity\UserApartment could not be converted to string
500 Internal Server Error - ContextErrorException
How can this error be fixed?
Thanks in advance!
You are trying to echo an object
echo ($userapt->key() . ' => ' . $userapt->current()) . "\n";
you can solve this by implementing the public function __toString() {} method in the UserApartament class. In this way when you will try to echo $user->current() it will use the __toString() method to show the string value of your object.
Related
how to display each record's values?
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
echo "Hello " . $snapshot['userId'];
I am receiving this error:
ErrorException
Object of class Google\Cloud\Firestore\DocumentReference could not be converted to string
print_r() function works correctly but how to access each individual record?
I have been searching for hours to get this solved but I found no reference on web
Please help me in here...
A snapshot contains both data and metadata about the document. To get the data you need to call its data() method:
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
if ($snapshot->exists()) {
printf('Document data:' . PHP_EOL);
echo "Hello " . $snapshot->data()['userId'];
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
Also see the Firebase documentation on getting a document from Firestore.
I am using the setup, I download and setup package from github with link below:
https://github.com/graphaware/reco4php
I have also installed the php7 and neo7j they are running properly on localhost (ubuntu16.04).
I am getting error in browser:
Fatal error: Uncaught Error: Class 'GraphAware\Reco4PHP\Demo\Github\RecommendationEngine' not found in /var/www/html/recommendation_2/example.php:9 Stack trace: #0 {main} thrown in /var/www/html/recommendation_2/example.php on line 9
when hit example.php form browser.example.php file code below:
<?php
// example.php file
require_once __DIR__.'/vendor/autoload.php';
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
$rs = RecommenderService::create("http://neo4j:idealindore#localhost:7474");
$rs->registerRecommendationEngine(new RecommendationEngine());
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$input = $rs->findInputBy('User', 'login', 'jakzal');
$engine = $rs->getRecommender("github_who_to_follow");
$stopwatch->start('reco');
$recommendations = $engine->recommend($input);
$e = $stopwatch->stop('reco');
//echo $recommendations->size() . ' found in ' . $e->getDuration() . 'ms' .PHP_EOL;
foreach ($recommendations->getItems(10) as $reco) {
echo $reco->item()->get('login') . PHP_EOL;
echo $reco->totalScore() . PHP_EOL;
foreach ($reco->getScores() as $name => $score) {
echo "\t" . $name . ':' . $score->score() . PHP_EOL;
}
}
Can anybody help me how can I solve this issue?
You are getting this error because you did not use the right path to the classes.
Change This :
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
to where you actually store These files.
RecommendationEngine.php
RecommenderService.php
Beside you also need to use these classes :
use GraphAware\Common\Cypher\Statement;
use GraphAware\Common\Type\Node;
use GraphAware\Reco4PHP\Context\Context;
use GraphAware\Reco4PHP\Engine\SingleDiscoveryEngine;
See This Link and follow the tutorial step by step to learn how to build a graph base recommendation system with Neo4J.
Also Check This Post if you have any problem with the tutorial.
I'm running xampp.
I created a basic db call mydb.sq3 and a basic table called panels. That all seems to work fine because when I call SELECT * FROM panels; from the command line it is all good. But there is an error that keeps getting thrown when i run my php file:
Fatal error: Call to undefined function query() in > C:\xampp\htdocs\example\myphp.php on line 10
<?php
$db = new SQLite3('mydb.sq3');
$result = $db-->query('SELECT * FROM panels');
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
echo $row['firstname'] . ': $' . $row['surname'] . '<br/>';
}
unset($db);
?>
Cheers
There is an error in line 3
Use this-
$result = $db->query('SELECT * FROM panels');
Instead of this -
$result = $db-->query('SELECT * FROM panels');
Simple typo error you used '--' instead of '-' Enjoy :)
Initially if there was one item in the list it would return an object rather than an array of one object. I fixed that using:
https://eirikhoem.wordpress.com/2008/03/13/array-problems-with-soap-and-php-updated/
$x = new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));
But I'm having problems when there is no items in the list.
The best I've come up with so far is:
$occulist = $result->GetWebOccurrencesResult->OccuList;
if (!empty((array)($occulist))) {
foreach($occulist->TOccu as $occurrence) {
echo $occurrence->Prog_Name . ' running from ' . $occurrence->StartDate . ' to ' . $occurrence->EndDate . '<br/>';
}
}
Originally it was
foreach($result->GetWebOccurrencesResult->OccuList->TOccu as $occurrence) {
I don't understand exactly what you're trying to achieve here, so if you can clarify in the comments, that'd be great.
What I'm taking from your question is that you want to handle when the array is empty, but want a clean method to do so? The loop you have there would do what you require, but here is another alternative:
do {
foreach($occulist->TOccu as $occurrence) {
echo $occurrence->Prog_Name . ' running from ' . $occurrence->StartDate . ' to ' . $occurrence->EndDate . '<br/>';
}
} while(empty((array)($occulist)) !== FALSE);
So you're looping through the foreach while the $occulist array isn't empty.
You could even do:
while((array)$occulist !== FALSE) {
foreach(....) {
...
}
}
On my server with Windows and PHP 5.4.23 this:
if (!empty((array)($occulist))) {
gives the following error:
Parse error: syntax error, unexpected '(array)' (array) (T_ARRAY_CAST)
I fixed it using:
if (get_object_vars($occulist)) {
I think that is a more elegant alternative to the original...
I created a new model in OpenCart in a folder called catalog/model/donate/campaign.
<?php
class ModelDonateCampaign extends Model {
public function addCampaign($data) {
$this->db->query("INSERT INTO `
" . DB_PREFIX . "campaign`
SET campaign_name = '" . $this->db->escape($data['campaign_name'])
. "', campaign_description = '" . $this->db->escape(['campaign_description'])
. "', campaign_startdate = '" . $this->db->escape($data['campaign_startdate'])
. "', campaign_enddate = '" . $this->db->escape($data['campaign_startdate'])
. " '")
return $order_id;
}
}
?>
In my controller I have...;
$this->language->load('donate/campaign');
$this->model_donate_campaign->addCampaign($data);
the error Im receiving is for when I try to call the last function...
Fatal error: Call to a member function addCampaign() on a non-object in C:\xampp\htdocs\charity\catalog\controller\donate\newcampaign.php on line 21
Is there part of the procedure that Im missing for setting up a model?
Thank you
you need to first load model like
$this->load->model('donate/campaign');
then use
$this->model_donate_campaign->addCampaign($data);
and don't use $this->language->load('donate/campaign'); if you have not created language file that is catalog/language/donate/campaign.php