Php 如何将SEOStats与Codeigniter集成?
你好,我想在codeigniter中集成一个项目,有人给我提供解决方案吗 我尝试将SEOstats类作为帮助器,并将帮助器加载到特定的控件中,但显示了一个空白页,我也尝试通过视图将其包括在内,但我看到的是同一个空白页 我已经在我的视图文件中包含了这段代码,SEOstats目录也在同一个视图目录中Php 如何将SEOStats与Codeigniter集成?,php,codeigniter,pagerank,alexa,Php,Codeigniter,Pagerank,Alexa,你好,我想在codeigniter中集成一个项目,有人给我提供解决方案吗 我尝试将SEOstats类作为帮助器,并将帮助器加载到特定的控件中,但显示了一个空白页,我也尝试通过视图将其包括在内,但我看到的是同一个空白页 我已经在我的视图文件中包含了这段代码,SEOstats目录也在同一个视图目录中 <?php require_once 'SEOstats/bootstrap.php'; use \SEOstats\Services as SEOstats; tr
<?php
require_once 'SEOstats/bootstrap.php';
use \SEOstats\Services as SEOstats;
try {
$url = 'http://www.google.com/';
// Create a new SEOstats instance.
$seostats = new \SEOstats\SEOstats;
// Bind the URL to the current SEOstats instance.
if ($seostats->setUrl($url)) {
echo SEOstats\Alexa::getGlobalRank();
echo SEOstats\Google::getPageRank();
}
}
catch (SEOstatsException $e) {
die($e->getMessage());
}
这就是我如何在我的Codeigniter网站上包括SEOStats的方法 希望这有帮助
附:复制应用程序/库文件夹中的SEOstats文件夹我知道这篇文章很旧。但我最近也在寻找解决方案,最后写了自己的,我想我会把它留在这里,以防将来有人在寻找解决方案 将以下内容放入库文件中,并根据需要自动加载
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class SEOstatistics {
private $seostats;
function __construct() {
require_once( APPPATH . 'third_party/seostats/bootstrap.php' );
$this->seostats = new \SEOstats\SEOstats;
}
private function alexa() {
return new \SEOstats\Services\Alexa;
}
private function google() {
return new \SEOstats\Services\Google;
}
private function moz() {
return new \SEOstats\Services\Mozscape();
}
private function openSiteExplorer() {
return new \SEOstats\Services\OpenSiteExplorer();
}
private function semRush() {
return new \SEOstats\Services\SemRush();
}
private function sistrix() {
return new \SEOstats\Services\Sistrix();
}
private function social() {
return new \SEOstats\Services\Social();
}
public function __call($method, $url) {
if (method_exists($this, $method)) {
if ($this->seostats->setUrl($url[0])) {
return call_user_func_array(array($this, $method),array());
}
return false;
}
}
}
在控制器或模型中使用它的示例如下:
$google = $this->seostatistics->google($url);
$rank = $google->getPageRank();
我认为这将是一个更好的加载作为一个图书馆。我用它作为一个图书馆,但它显示空白页,你张贴你的代码,你如何使用它作为一个图书馆?我编辑了我的问题感谢很多@安东尼,非常有用!你能不能也看看这个图书馆的问题:?
class Cron extends Frontend_Controller
{
public function get_google_page_rank() {
require_once (APPPATH . 'libraries/SEOstats/bootstrap.php');
try {
$url = 'http://www.google.com/';
// Get the Google PageRank for the given URL.
$pagerank = \SEOstats\Services\Google::getPageRank($url);
echo "The current Google PageRank for {$url} is {$pagerank}." . PHP_EOL;
}
catch(\Exception $e) {
echo 'Caught SEOstatsException: ' . $e->getMessage();
}
}
public function get_alexa_page_rank() {
require_once (APPPATH . 'libraries/SEOstats/bootstrap.php');
//use \SEOstats\Services\Alexa as Alexa;
try {
$url = 'https://www.google.com/';
// Create a new SEOstats instance.
$seostats = new \SEOstats\SEOstats;
// Bind the URL to the current SEOstats instance.
if ($seostats->setUrl($url)) {
/**
* Print HTML code for the 'daily traffic trend'-graph.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(1);
/**
* Print HTML code for the 'daily pageviews (percent)'-graph.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(2);
/**
* Print HTML code for the 'daily pageviews per user'-graph.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(3);
/**
* Print HTML code for the 'time on site (in minutes)'-graph.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(4);
/**
* Print HTML code for the 'bounce rate (percent)'-graph.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(5);
/**
* Print HTML code for the 'search visits'-graph, using
* specific graph dimensions of 320*240 px.
*/
echo \SEOstats\Services\Alexa::getTrafficGraph(6, false, 320, 240);
}
}
catch(\Exception $e) {
echo 'Caught SEOstatsException: ' . $e->getMessage();
}
}
}
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class SEOstatistics {
private $seostats;
function __construct() {
require_once( APPPATH . 'third_party/seostats/bootstrap.php' );
$this->seostats = new \SEOstats\SEOstats;
}
private function alexa() {
return new \SEOstats\Services\Alexa;
}
private function google() {
return new \SEOstats\Services\Google;
}
private function moz() {
return new \SEOstats\Services\Mozscape();
}
private function openSiteExplorer() {
return new \SEOstats\Services\OpenSiteExplorer();
}
private function semRush() {
return new \SEOstats\Services\SemRush();
}
private function sistrix() {
return new \SEOstats\Services\Sistrix();
}
private function social() {
return new \SEOstats\Services\Social();
}
public function __call($method, $url) {
if (method_exists($this, $method)) {
if ($this->seostats->setUrl($url[0])) {
return call_user_func_array(array($this, $method),array());
}
return false;
}
}
}
$google = $this->seostatistics->google($url);
$rank = $google->getPageRank();