我从 ftp 下载了一个网站。该网站是用 CodeIgniter 制作的。我的问题是它似乎在本地主机上不起作用。
config.php 中的基本 URL:
$config['base_url'] = 'http://sample_localhost/mysite/';
database.php 中的设置:
$db['default']['hostname'] = 'sample_localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'admin';
$db['default']['database'] = 'my_database';
非常感谢任何帮助。提前致谢!
最佳答案
1) 下载最新版CodeIgniter .
2) 将其解压缩并将解压缩的文件夹粘贴到“htcdocs”目录中。在我的场景中,我使用的是 XAMPP 1.8.1,所以我将把它粘贴到同一目录中。此外,您可以重命名文件夹,例如CI.
3)首先查看您的配置文件并进行一些修改。
autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
config.php
$config['base_url'] = 'your localhost url';
以我为例:
$config['base_url'] = 'http://localhost/CI/index.php/'; // your current URL on the address bar when displaying the welcome_message
$config['index_page'] = 'index.php'; // page where you want your viewers are redirected when they type in your website name
例如base_url — http://www.example.com/ index_page — index.php 或直接转到 news.php,由您决定
routes.php
$route['default_controller'] = 'site' // your controller's method, originally "welcome" to display welcome message
我将“site”设置为默认 Controller
数据库.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = '[your database]'; // e.g. CI_series
$db['default']['dbdriver'] = 'mysql';
提示:如果您还没有任何访问数据库的权限,则默认用户名将是 root。另外,暂时将密码留空。
4) 开始使用 Controller Controller 是应用程序的核心,因为它们决定了应如何处理 HTTP 请求。 Controller 只是一个类文件,其命名方式可以与 URI 相关联。
例如
http://www.example.com/index.php/blog/
在上面的例子中,CodeIgniter 会尝试找到一个名为 blog.php 的 Controller 并加载它。
当 Controller 的名称与 URI 的第一段匹配时,它将被加载。
现在,让我们为我们的 Controller 输入代码。
<?php
class Site extends CI_Controller
{
function index()
{
$this->load->view('home.php');
}
}
?>
基本上,这只会加载名为 home
的 View /页面* 什么是负载?
Loader,顾名思义,就是用来加载元素的。这些元素可以是库(类) View 文件、助手、模型或您自己的文件。 (ref)
此代码片段可让您显示页面 home.php。此外,由于您正在调用 home.php,因此您必须将此页面放在 views 文件夹下。创建您的 home.php,编写您想要显示的任何内容作为我们第一次运行的测试并保存。
此代码片段可让您显示页面 home.php。此外,由于您正在调用 home.php,因此您必须将此页面放在 views 文件夹下。创建您的 home.php,编写您想要显示的任何内容作为我们第一次运行的测试并保存。
home.php
<p>
My view has been loaded. Welcome!
</p>
另外,将我们的 Controller 保存在controllers文件夹下,文件名要和你的类名一样。在这种情况下,它应该保存为 site.php。
第一次运行:
关于php - CodeIgniter 无法在本地主机上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980749/