I'm currently getting this error while migrating to a online provider
Fatal error: Uncaught Error: Class 'app\Http\model\MoviePresenter' not found in /home/index.php:4 Stack trace: #0 {main} thrown in /home/index.php on line 4
This code works locally fine it's just decided to stop working on the host.
below is some of the code
<?php ini_set('display_errors', 1);
$moviePresenter = new \app\Http\model\MoviePresenter; $movieGenreList = $moviePresenter->getMovieGenreList();
function displayMovieList($movieList, $moviePresenter)
{
$html = '<div class="movie-list row">';
$currentURL = \Request::root();
foreach ($movieList as $movie) {
$genreList = $movie->getGenres();
$movieGenreList = $moviePresenter->getMovieGenreList();
foreach ($genreList as $genre){
foreach ($movieGenreList['genres'] as $movieGenre){
if($genre->getID() == $movieGenre['id']){
$genre->setName($movieGenre['name']);
}
}
}
$movieID = $movie->getID();
$image = $movie->getPosterImage();
$poster = '<img class="img-responsive" src="//image.tmdb.org/t/p/w154/'. $image .'" width="195" height="360">';
$html .= '<div class="col-xl-3 col-lg-4 col-md-6 col-sm-12 d-flex align-items-center flex-column justify-content-center h-100"><a
href="' . $currentURL . '/movie/' . $movieID . '">';
$html .= $poster;
$html .= '</a><div class="moviedetails row">';
foreach($genreList as $genre){
$html .= '<a href="'. $currentURL . '/discovery/genre/'. $genre->getID() . '" class="genres">';
$html .= $genre->getName() . '</a>';
}
$html .= '</div></div>';
$html .= '</div>';
return $html;
}
?>
It looks like it's looking within the view (where the snipit is from) for the class instead of the file path.
Can anyone tell me why it's searching the local class instead of the view?
It may be because of case sensitivity issues. I bet your new host is Linux, so your namespace should be:
\App\Http\model\MoviePresenter
or \App\Http\Model\MoviePresenter
instead of app\Http\model\MoviePresenter
The laravel App namespace use Uppercase A.
I don't know which Laravel version you are using. You should give more details regarding your question.
Try importing the MoviePresenter model at the beginning in your file like this
use App\MoviePresenter;
or according to your model file directory like this
use App\Http\model\MoviePresenter;
The error Class 'app\Http\model\MoviePresenter' not found, when you use new class MoviePresenter, but you haven't imported the Class MoviePresenter.
So you should import the class MoviePresenter in the file index.php, try using require() at the beginning in your file like this:
require('app\Http\model\MoviePresenter');
//PUT YOUR OTHER CODE BELOW THIS
Related
I have this shortcode (I wrote it in functions.php) that shows the read previous and read next links in a single post:
<?php
function prev_next_buttons_post() {
$html = '';
$html .= '<div class="container-single-post-buttons">';
$html .= '<div class="prev-next-buttons">' . previous_post_link('%link', '< read previous') . '</div>';
$html .= 'back to blog';
$html .= '<div class="prev-next-buttons">' . next_post_link('%link', 'read next >') . '</div>';
$html .= '</div>';
return $html;
}
add_shortcode('prev_next_buttons', 'prev_next_buttons_post');
The problem I have is that when I add the shortcode:
<section>
<div class="container btd-container-sm">
<?php echo do_shortcode('[prev_next_buttons]') ?>
</div>
</section>
when inspecting it shows the different structure and the links are outside their containers losing their styles:
I need them to be in the same structure as defined in my shortcode.
How could I solve this? Please help.
This is because previous_post_link and next_post_link do not return a value, but write to the output buffer directly.
You need to use their counterparts that return the value, so that you can then concatenate those into your string - get_previous_post_link and get_next_post_link.
(If you check the source code for the former two functions, you’ll see that they are just wrapper functions that call the latter two, and echo their return values - https://developer.wordpress.org/reference/functions/previous_post_link/#source)
I'm trying to implement the phpFlickr-wrapper (https://github.com/dan-coulter/phpflickr) in my MODX-project.
I tried a simple code i found here on stackoverflow and put it in a snippet called "Flickr":
//include the core file
if(!class_exists("phpFlickr")) require_once './assets/phpflickr-master/phpFlickr.php';
// include the config file
require_once('./assets/phpflickr-master/config.php');
$f = new phpFlickr($key, $api_secret);
$mySetID = $album;
$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
echo '<div><img src="'. $f->buildPhotoURL($photo, 'medium') .'" alt="" /></div>';
}
The snippet call:
[[!Flickr? &setname=`[[+tv.FickrID]]`]]
The TV "FlickrID" holds the ID of the wanted album.
This is working fine for one album. But when I try to output a second gallery the output gets stopped after the first snippet-call. The second time the snippet-call is made it stops with this entry in the MODX error-log:
...75.include.cache.php : 18) PHP warning: Invalid argument supplied for foreach()
How can I display more than one album on the same page, any idea?
Problem solved...
I just had to include the content from the "config.php"-file inside the snippet, rather than referring to it by the "require_once"-line of code.
<?php
$album = $modx->getOption('setname',$scriptProperties,'');
//include the core file
if(!class_exists("phpFlickr")) require_once './assets/phpflickr-master/phpFlickr.php';
if(!class_exists("PEAR")) require_once './assets/phpflickr/PEAR/PEAR.php';
$key = "<flickr-api-key>";
$api_secret = "<flickr-api-secret>";
$username="<flickr-username>";
$f = new phpFlickr($key, $api_secret);
$f->enableCache("fs", "./assets/phpflickr-master/cache");
$mySetID = $album;
$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
$output .= '<div><a rel="lightbox[]" href="'. $f->buildPhotoURL($photo, 'large') .'"><img src="'. $f->buildPhotoURL($photo, 'medium') .'" alt="" /></a></div>';
}
return $output;
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.
Im creating a custom function for my wordpress website that will add a review section below the post content and i need to insert this function from another another file into a custom function that i added to my functions.php. I need to get this piece of code $buffy .= $this->get_review(); from a different file to work in this function:
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' ))) {
$top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off' ))) {
$bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single()) {
$review = //HOW DO I ADD THAT get_review CODE HERE?
$custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
$facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
}
$content = $top_ad . $content . $bottom_ad . $custom_share . $facebook_comments;
return $content;
}
add_filter('the_content', 'content_injector');
As you can see i need to add the get_review function to $review, but i cant make it work on my own. How to make this work?
Use include to include the file before using any methods from that file.
include("file_with_functions.php");
OR
Create a class (with filename same as classname).
Include the file.
Create an instance of the class.
Access the method in the class through the object
I have a class with a method called paint() so i call $object->paint(); and it returns the html code to display the object the way i like it.
In a function, i have an array of those objects, so i do something like this:
$code = '<p class="wrapper">';
foreach( $object_arr as $object ){
$code .= $object->paint();
}
$code .='</p>';
echo $code;
but the result iḿ getting is this:
<p class="wrapper"></p>
<figure id="f1">Figure 1</figure>
<figure id="f2">Figure 2</figure>
...
<figure id="fn">Figure n</figure>
The function paint() returns the code to paint the object, i was expecting to see:
<p class="wrapper">
<figure id="f1">Figure 1</figure>
<figure id="f2">Figure 2</figure>
...
<figure id="fn">Figure n</figure>
</p>
What am i doing it wrong?
The result you're looking at might be corrected by your browser. p does not accept figure as a child, so the browser might correct it by closing your first <p class="wrapper">.
Some more code would be helpful, but this might put you on the right track.
What is $object_arr an array of. Can you post the example of the object in the object array?
With my example you would have to pass in the index as well to get the id="fnn".
If you post some more code I can clarify my answer.
<?php
function paint($str){
return '<figure id="fn">'.$str.'</figure>';
}
$object_arr =Array('happy','beans');
$code = '<p class="wrapper">';
foreach( $object_arr as $object ){
$code .= paint($object);
}
$code .='</p>';
echo $code;
If you're using single quotes, then put a tab before the method call:
$code .= ' ' . $object->paint();
But this would be easier:
$code .= "\t" . $object->paint();