致命错误:无法重新声明site_url() [英] Fatal error: Cannot redeclare site_url()

查看:288
本文介绍了致命错误:无法重新声明site_url()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在codeigniter工作,我想在我的网络上获取博客帖子

I am working in codeigniter and I want to fetch blog post on the my web

网站首页当我包含两个文件

Site Homepage When I include two file

require_once('blog/wp-blog-header.php');
require_once('blog/wp-includes/link-template.php');

我遇到了错误。

Fatal error: Cannot redeclare site_url() (previously declared in /home/homebidpro/public_html/dev/system/helpers/url_helper.php:83) in /home/homebidpro/public_html/dev/blog/wp-includes/link-template.php on line 3004

我根据位置文件注释了此函数:

I Commented this function according to location file:

function site_url( $path = '', $scheme = null ) {
    return get_site_url( null, $path, $scheme );
}

此错误被删除,网站wotks的所有功能但是当我打开
博客未打开它是给错误

this error is removed and all functionality of website wotks But When I open blog is not opening it is giving error

dev.homebidpro.com页面无效

博客和项目位置在dev文件夹中都是相同的。

Blog and project location is same both are in dev Folder.

我坚持到现在。请尽快提供解决方案。

I stuck till now. Please give the solution as soon as possiable.

其余代码是

 public function blogData()
    {

        require_once('blog/wp-blog-header.php');
        require_once('blog/wp-includes/link-template.php');

        if($catagory !='')
        {

            $args = array(  'posts_per_page' => 3, 'category_name' => $catagory );
        }
        else
        {

            $args = array('posts_per_page' => 4);
        }    

        $mypostsMov = get_posts( $args );  
       // echo "<pre>"; print_r($mypostsMov); die;
        $mypostsarrayMov = array();
        $i=0;
        foreach ($mypostsMov as $post ) : 
        $excerpt = preg_replace("/<img[^>]+\>/i", "", $post->post_content);      
        $mypostsarrayMov[$i]['post_title'] = strip_tags($post->post_title);
        $mypostsarrayMov[$i]['content'] =    strip_tags($post->post_content);
        $mypostsarrayMov[$i]['permalink'] = get_permalink($post->ID);
        $mypostsarrayMov[$i]['thumbnail'] =get_the_post_thumbnail($post->ID,array( 300, 200));
        $i++;
        endforeach; 
        wp_reset_postdata();

         //echo "<pre>"; print_r($mypostsarrayMov); die;

         //return $this->render('MovePlusServiceBundle:Default:recentpostCombined.html.twig',array('mypostsMov'=>$mypostsarrayMov, ));

         return $mypostsarrayMov;

}

site_url 函数

if ( ! function_exists('site_url'))

{

    function site_url($uri = '')
    {
        $CI =& get_instance();
        return $CI->config->site_url($uri);
    }

}

和siteurl函式我已经给你。

and siteurl function which is blog folder I already send you.

推荐答案

你有的问题是CodeIgniter有一个 site_url code>函数,位于网址助手中,和Wordpress也有一个函数 site_url()它定义在 wp-includes / link-template.php文件

The issue you have is that CodeIgniter has a site_url() function in the url helper, and Wordpress also has a function site_url() which is defined within the wp-includes/link-template.php file.

因为你在CodeIniter页面中包含了link-template.php,PHP告诉你

Because you've included link-template.php in your CodeIniter page, PHP is telling you you're trying to create a function which already exists, which you can't do.

从我可以想到的,你需要:

From what I can think of, you need to either:


  • 不要在您包含Wordpress的网页上加载CodeIgniter网址帮助程序,或

  • 不要加载当您加载CodeIgniter网址帮助程序时,或者

  • 将wp-includes / link-template.php文件中需要的功能复制到自定义库/帮助器或您的控制器,以便您可以生成需要包含文件的结果。

您可以选择实现这些

这篇关于致命错误:无法重新声明site_url()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆