- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我是 CodeIgniter 的新手。我需要处理一个表格。我在 View 中有一个 form.html 页面
<html>
<head>
<title>Search</title>
</head>
<body>
<form action="search">
<input type="text" name="search" value="" size="50" />
<div>
<input type="submit" value="Submit" />
</div>
</form>
</body>
</html>
和表单 Controller
class Form extends Controller {
function Form() {
parent::Controller();
}
function index() {
$this->load->view('form');
}
}
我有一个 View 文件 search.php 但是当它被处理时它显示找不到页面...
最佳答案
在 M.odel V.iew C.ontroller 设置中,如 CodeIgniter, View 是用户界面元素。他们不应该解析结果。
如果我没记错的话,您要做的是将数据从 www.yoursite.com/index.php/form
传递到 www.yoursite.com/index.php/搜索
在非结构化 php 中,您可能有一个带有 search.php
表单操作的 form.html
。用户将导航到 yoursite.com/form.html
,这将调用 yoursite.com/search.php
,这可能会重定向到 yoursite.com/results .php
.
在 CodeIgniter 中(据我所知,在任何 MVC 系统中,无论语言如何)你的 Controller , Form
调用加载 form.html
的函数 View 进入自身,然后运行它。 View生成用户与之交互的代码(通常是 HTML,但不一定)。当用户发出 View 无法处理的请求(请求更多数据或其他页面)时,它会将请求传回 Controller , Controller 加载更多数据或其他 View 。
换句话说, View 决定了数据将如何显示。 Controller 将请求映射到 View 。
当您希望在 View 中显示复杂和/或不断变化的数据时,情况会稍微复杂一些。为了维护 separation of concerns MVC 需要 CodeIgniter 还为您提供 Models .
模型负责任何网络应用程序中最困难的部分——管理数据流。它们包含读取数据、写入数据的方法,最重要的是,还包含确保数据完整性的方法。换句话说,模型应该:
Akelos有一个很好的图形来布置 MVC 的组件:
(来源:akelos.org)
也就是说,完成您想要做的事情的最简单(读作“最简单”,而不是“最可扩展”)方法是:
function Form()
{
parent::Controller();
}
function index()
{
$this->load->view('form');
}
function search()
{
$term = $this->input->post('search');
/*
In order for this to work you will need to
change the method on your form.
(Since you do not specify a method in your form,
it will default to the *get* method -- and CodeIgniter
destroys the $_GET variable unless you change its
default settings.)
The *action* your form needs to have is
index.php/form/search/
*/
// Operate on your search data here.
// One possible way to do this:
$this->load->model('search_model');
$results_from_search = $this->search->find_data($term);
// Make sure your model properly escapes incoming data.
$this->load->view('results', $results_from_search);
}
关于php - 如何使用 CodeIgniter 处理表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2279282/
我想扩展调用 getMessage 时返回自定义消息的异常类。 class MY_Exceptions extends CI_Exceptions{ function __construct
我已经安装了一个干净的 Apache2(加上 PHP 和 MySQL)服务器并启用了 mod_rewrite在 apache 配置中。 我添加了 .htaccess文件以从 url 中删除 index
我正在使用上传类上传图片。但是我上传的图片的存储位置是:http://www.mysite.com/uploads/ 此文件夹的绝对路径是:c:\wamp\www\mysite\uploads\ 应用
大家好 我想在codeigniter上下文中提供一些静态html页面。我不想绕过base_url中的index.php文件。 但是,当我使用对HTML文件的调用时,它不会显示404错误页面。 感谢已经
我一直想知道在模型中以 OO 风格编写代码的正确方法是什么。当然,您可以拥有一个从数据库中检索数据然后映射到模型级变量的函数。但是,当您在模型中有其他功能试图从 BD 获取其他数据时,这种方法会变得违
之前所有的 JOIN 尝试都给我留下了填充结果的 id、标题键的光盘或项目数据(可能发生了冲突)。 所以我有: item table fields: id, title disc table fiel
假设我在 Controller 中有一个名为 的方法 book($chapter,$page); 其中 $chapter 和 $page 必须是整数。要访问该方法,URI 将如下所示 book/cha
我有一个用户可以注册的页面。他在此过程中上传了个人资料照片。我想限制大小,但除了 $config['maxsize'] 之外,并没有太多强调 codeigniter 文档。我尝试了以下但我没有收到任何
我需要将 CodeIgniter 设置为真正的多语言网站。我已经搜索过,但找不到解决方案。 我已经测试了这种方法,但它不起作用。 ( http://codeigniter.com/wiki/Categ
CodeIgniter 中的常量是否可以用于整个站点中的重复文本(比如元标记和元描述)?就像是: define('METADESCRIPTION', 'This is my site'); 然后将 M
我已经在 CodeIgniter 的路由器中写了这个。 $route['companyname'] = "/profile/1"; 这工作正常,但是当我在 URL 中键入“公司名称”时,它不起作用。这
我正在开始我的第一个 CodeIgniter 项目,并希望在开始之前获得一些建议。我对 Controller 和模型的名称如何工作感到有些困惑。 如果我希望我公司页面的网址为 http://examp
可以在CodeIgniter Active Record中使用多个INSERT记录,而无需for,foreach等。 我当前的代码: foreach($tags as $tag) { $tag
SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace); 如何在 CodeIgniter 事件记录中编写上述 select
wkhtmltopdf 听起来是一个很好的解决方案...问题是 exec 上没有任何反应 shell_exec("c:\wkhtmltopdf.exe","http://www.google.com
我当前的CodeIgniter有点问题。我有一个带有“页面” Controller 的CI安装程序,该 Controller 可从/ views加载静态文件,但它最多只能包含1个子文件夹,而我正在向其
有一段时间,我一直在处理分页类中的一个问题。 问题是,除了第 1 页的链接之外,所有分页的内容都可以。 所有链接都是这样的: example.com/method/page/2 example.com
我想对请求进行一些预处理和后处理,例如处理身份验证、加载上下文数据、性能时间等等。来自 Django 的概念是 MIDDLEWARE_CLASSES这让我可以在各个阶段处理请求:https://doc
我想通过创建自己的库和配置文件在 CodeIgniter 中生成全局变量。这就是我在我的库文件中编写的,比如说 globalvars.php。我把它放在/application/libraries 中
我有以下分页样式 Previous Page
我是一名优秀的程序员,十分优秀!