无法在外部php脚本中包含codeigniter控制器文件 [英] Could not include codeigniter controller files in external php script

查看:165
本文介绍了无法在外部php脚本中包含codeigniter控制器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用这个代码形式外部php脚本包括codeigniter控制器文件。

i have used this code form external php script to include the codeigniter controller file.

include_once "codeigniter/index.php/user";

无效。

'user'是我的控制器文件。

但是我可以通过 '默认控制器页

However i can include by making 'user' the default controller page

$route['default_controller']="user";

并用作:

include_once "codeigniter/index.php";

但是如果我需要其他控制器文件怎么办?

but what if i need other controller files?

更新:

此外,控制器文件可以通过外部php脚本链接:

Also, the controller file could be linked through external php script:

<a href="codeigniter/index.php/user">click here</a>


推荐答案

CodeIgniter可以被告知加载默认控制器URI不存在,如果只请求您的网站根URL的情况下。要指定默认控制器,请打开 application / config / routes.php 文件并设置此变量:

CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:

$route['default_controller'] = 'User';

其中用户是控制器的名称类。如果现在加载主要的 index.php 文件而不指定任何URI段,则默认情况下会显示Hello World消息。

Where User is the name of the controller class you want used. If you now load your main index.php file without specifying any URI segments you'll see your Hello World message by default.

在您的情况下,您可以通过以下方式调用任何控制器: -

In your case, you can call any controller by:-

http://localhost/codeigniter/index.php/controller_name/method_name/

教学链接会更好地解释:)

请使用 cURL

  $curl_handle=curl_init();
  curl_setopt($curl_handle,CURLOPT_URL,'Your_CI_CONTROLLER_URL');
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  $buffer = curl_exec($curl_handle);
  curl_close($curl_handle);
  if (empty($buffer)){
      print "Nothing returned from url.<p>";
  }
  else{
      print $buffer;
  }

这篇关于无法在外部php脚本中包含codeigniter控制器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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