php 如何在 codeigniter 中开始一个新的网站项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15652357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start a new website project in codeigniter?
提问by Qadir Hussain
I'm really beginner to codeigniter
I'm working on CI since last 2 weeks. During this period I have created many views.php files, some controllers.php files and some models.php files
codeigniter
自过去两周以来,我真的是初学者,我一直在从事 CI 工作。这期间我创建了很多views.php文件,一些controllers.php文件和一些models.php文件
Now I want start a new website project.
现在我想开始一个新的网站项目。
What should I do. Should I delete all files of my controllers, views and models, etc., and download another codeigniter
and start from the beginning?
我该怎么办。我应该删除我的控制器、视图和模型等的所有文件,然后下载另一个codeigniter
并从头开始吗?
采纳答案by Shaolin
Here is Phil Sturgeon's article on how to do multiple site on one CI instance, in here he explains 2 ways of doing it and describes pros and cons.
这是 Phil Sturgeon 关于如何在一个 CI 实例上执行多个站点的文章,在这里他解释了两种方法并描述了优缺点。
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
But in his latest articles he has told what happened to modular separation.
但在他最新的文章中,他讲述了模块化分离发生了什么。
http://philsturgeon.co.uk/blog/2010/03/modular-separation-codeigniter-2
http://philsturgeon.co.uk/blog/2010/03/modular-separation-codeigniter-2
回答by Muhammad Nasir
You should check the documentation of codeigniter for help but just to give you a quick start ill explain how to create your first codeigniter project.
您应该查看 codeigniter 的文档以获取帮助,但只是为了让您快速入门并解释如何创建您的第一个 codeigniter 项目。
Installation 1 Download the codeigniter framework from http://ellislab.com/codeigniter2 upload it in root directory of your website or local apache server directory.
安装 1 从http://ellislab.com/codeigniter下载 codeigniter 框架 2 上传到您网站的根目录或本地 apache 服务器目录。
Creating your codeigniter project. In codeigniter your controller will handle the url requests and load appropriate model and views. So the first step is to create your controller.
创建您的 codeigniter 项目。在 codeigniter 中,您的控制器将处理 url 请求并加载适当的模型和视图。所以第一步是创建你的控制器。
1 Creating your controller: go to Applications->controllers and there you will find a built in controller called welcome.php. This controller loads a view welcome_message.php which is inside Application->views. You can use this controller or create your own. To create your own controller create a new php file myfirstcontroller.php and extend a class with same name from CI_Controller. Note that the name of the file and your class name should be the same. the index function is the default function that will be called when you make a request to the controller
1 创建您的控制器:转到 Applications->controllers,您将在那里找到一个名为welcome.php 的内置控制器。这个控制器加载了一个视图welcome_message.php,它位于Application->views 中。您可以使用此控制器或创建自己的控制器。要创建您自己的控制器,请创建一个新的 php 文件 myfirstcontroller.php 并从 CI_Controller 扩展一个具有相同名称的类。请注意,文件名和您的类名应该相同。index 函数是您向控制器发出请求时将调用的默认函数
class myfirstcontroller extends CI_Controller {
public function index(){
$this->load->view("myfirstview");
}
}
so when you request this controller through yoursite/index.php/myfirstcontroller
所以当你通过 yoursite/index.php/myfirstcontroller 请求这个控制器时
it will load a view called myfirstview.php which will reside inside applications->views.
它将加载一个名为 myfirstview.php 的视图,该视图将位于应用程序->视图中。
Go ahead and create this file in applications ->views.
继续并在应用程序 -> 视图中创建此文件。
2 To pass data from controller to view you will send an array to the view
2 要将数据从控制器传递到视图,您将向视图发送一个数组
class myfirstcontroller extends CI_Controller {
public function index(){
$data['name']="My first application.";
$this->load->view("myfirstview",$data);
}
}
3 You can access this variable in view
3 可以在view中访问这个变量
echo $name
and it will output your variable
它会输出你的变量
3 you use models you have to create a file inside applications->models and call it from controller and it will return the result in the form of array.
3 你使用模型你必须在应用程序->模型中创建一个文件并从控制器调用它,它将以数组的形式返回结果。
You can look at the documentation for further help.
您可以查看文档以获得进一步的帮助。
Hope this helped you to get started with codeigniter.
希望这能帮助您开始使用 codeigniter。
The user guide is inside your download library.
用户指南位于您的下载库中。
You can also view it in http://ellislab.com/codeigniter/user-guide/
您也可以在http://ellislab.com/codeigniter/user-guide/ 中查看
Good luck!!!
祝你好运!!!