i'm a beginner in using laravel. For my webapp I want to use the Google API PageSpeed. When visiting /pagespeed, it gives me this error: ErrorException (E_NOTICE) Undefined property: stdClass::$ruleScore
Also i'm not sure if i made a correct return. I just want to show the meassured data on the /pagespeed page.
Couldn't really find an answer for my problem, I hope you can help.
I used the pagespeed.php code from http://ift.tt/2zFJnmU and put this in my PagespeedController:
public function pageSpeed(){
$url = 'http://ift.tt/g8FRpY';
$key = 'my API key';
// View http://ift.tt/2hpTMbZ to get a key
$data = json_decode(file_get_contents("http://ift.tt/2zEtcpD"));
$dat = $data->formattedResults->ruleResults;
foreach($dat as $d) {
$name = $d->localizedRuleName;
$score = $d->ruleScore;
print "\nTest: " . $name . "\n";
print "Score: " . $score . "\n";
if ($score != 100) {
if (isset($d->urlBlocks[0]->header->args)) {
$advice_header = replace_placeholders($d->urlBlocks[0]->header->format, $d->urlBlocks[0]->header->args);
}
else {
$advice_header = $d->urlBlocks[0]->header->format;
}
print "Advice: " . $advice_header . "\n";
foreach ($d->urlBlocks[0]->urls as $url) {
$advice = replace_placeholders($url->result->format, $url->result->args);
print $advice . "\n";
}
}
};
function replace_placeholders($format, $args) {
$i = 1;
foreach ($args as $arg) {
$format = str_replace("\$" . $i, "$arg->value", $format);
$i++;
}
return view('pagespeed')->with('format');
}
This is in my views folder: pagespeed.blade.php:
@extends('layouts.app')
@section('content')
<h1>Page Speed</h1>
@endsection
This is my Route in web.php:
Route::get('/pagespeed', 'PagespeedController@pageSpeed');
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2idTjuk
via IFTTT
Aucun commentaire:
Enregistrer un commentaire