How to call the instance of class? - php

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.

Related

Showing message Twig_Error_Loader in open cart

I am using open cart version 3. And I got the following message: Twig_Error_Loader in open cart after replacing theme files.
Full error:
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'Unable to
find template "common/column_left.twig" (looked into:
C:/xampp/htdocs/fast/catalog/view/theme).' in
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php:215
Stack trace: #0
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php(139
Twig_Loader_Filesystem->findTemplate('common/column_l...') #1
C:\xampp\htdocs\fast\system\library\template\Twig\Environment.php(312):
Twig_Loader_Filesystem->getCacheKey('common/column_l...') #2
C:\xampp\htdocs\fast\system\library\template\Twig\Environment.php(378):
Twig_Environment->getTemplateClass('common/column_l...', NULL) #3
C:\xampp\htdocs\fast\system\library\template\twig.php(52): Twig_Environment-
>loadTemplate('common/column_l...') #4
C:\xampp\htdocs\fast\system\library\template.php(22): Template\Twig-
>render('common/column_l...', false, 'fastor') #5
C:\xampp\htdocs\fast\system\engine\loader.php(86): Template-
>render('common/column_l...', Object(Registry), '1') #6 C:\xampp\ in
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php on
line 215
Your help will be greatly appreciated
it looks that the problem resides in
catalog/controller/event/theme.php
the Code assigns a path only when $theme:info isn't set.
if ($theme_info) {
$template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}elseif (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $theme . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}
I modified the code to this.
Now a path is asigned and the whole thing works. You still have to reload the cache to see modification.
if ($theme_info) {
$template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}
if (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $theme . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}
Solved in the following way. In the admin panel, go to Design-> template editor, on the right "History" Find and delete common/column_left. The left column will be rolled back "by default" If you need to make changes to it, do it in the column_left.twig file and upload it to the server, update the cache.

php file isn't recognising my sqlite3 db mydb.sq3

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 :)

Catchable Fatal Error: Object of class stdClass could not be converted to string in error on live site only

I have a test (localhost) website and a live site that use the same PHP code. I am getting the following error ONLY on my live site (doesn't happen on the localhost version using the same codebase.
Catchable Fatal Error: Object of class stdClass could not be converted
to string in .... on line 486.
Note - line 486 is this line within the foreach loop - any ideas why it isn't working on live but ok for localhost?
$out .= sprintf("<tr><td>%s</td><td>%s</td></tr>", $error['title'], $error['description']);
Code Block
public function getErrorTable()
{
$support_email_link = "<a href='" . $this->support_email . "'>" . $this->support_email . "</a>";
$out = '<div style="width:100%;min-height:380px;text-align:center;"><p style="font-size: 30px;">Error encountered <i class="fa fa-times" style="color:#CC0000;"></i></p><span>Please contact ' . $support_email_link . "</span><br><table id='error_table'><thead><th>Error Title</th><th>Description</th></thead><tbody>";
foreach ($this->errors as $error) {
$out .= sprintf("<tr><td>%s</td><td>%s</td></tr>", $error['title'], $error['description']);
}
$out .= "</tbody></table></div>";
return $out;
}
I don't know what $this->errors is containing when getErrorTable is called, but the error message indicates that either $error['title'] or $error['description'] is an object, rather than a string.
Now, this can be caused by many things, from different PHP configuration to a different execution flow on your website. This is hard to tell from just this snippet. The easiest way for you to debug this issue is to simply print_r($error) in your foreach, or error_log(print_r($error, true)) if the website is in production and you don't want to just dump information to your visitors (which is probably a bad idea!).

ArrayObject::getIterator error

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.

AWS SDK PHP iterator

I've written a small function (in PHP) to return all AWS instances in my account.
I've tried using the basic describe instances method but it times out (see below).
So the new function uses the getIterator, however, the page still times out. If it set the max results to 10 it works, but I think that defeats the object. I want a full list of all of my instances.
Any thoughts on what I might be doing wrong that would cause my request to time out? The time out message I get is:
Unable to load the webpage because the server sent no data. Error code: ERR_EMPTY_RESPONSE"
public function allInstances(){
$response = $this->ec2Client->getIterator('describeInstances',array(
'Filters' => array(
array(
'Name' => 'instance-state-name',
'Values' => array('running')
)
))
);
return $response;
}
Update to original post:
This is my code for iterating through the results return by the describeInstances itertator. I know I have around 400 instances running, however the result never returns anything more than about 280.
foreach($iterator as $object){
$value = $object['Reservation'];
//echo "<pre>" . print_r($object,true) . "</pre>";
$number = $count++;
echo $count . ">" . "<b>InstanceID: </b>" . $object['InstanceId'] . " <b>AMI: </b>" . $object['ImageId'] . "</br>";
}

Categories