我刚开始使用CodeIgnitor,这是我第一次使用MVC结构,我有一个以前从未见过的问题.它主要是在“表单”部分,但也在数据库显示。
我也用Xampp。
我有一个表单来创建要插入数据库中的项,但是只要单击submit按钮,url部分就会出错。
我的基本URL是: localhost/CodeIgniter-3.1.1/ (CodeIgniter-3.1.1是包含每个php文件夹的目录)。
所以表单页面URL是: localhost/CodeIgniter-3.1.1/index.php/news/create
当我提交时,它是: localhost/CodeIgniter-3.1.1/index.php/news/localhost/CodeIgniter-3.1.1/index.php/news/create
它只是在控制器后重复整个URL (新闻)。我不认为它必须与config.php,我的基本网址似乎很好,我只是不知道。
发布于 2016-10-24 16:50:11
使您的基本url http://localhost/Codeigniter-3.1.1/index.php/,然后在您的<form>标记中设置url像下面的<form method="post" action="<?= base_url('news/create') ?>">
发布于 2016-10-24 18:10:36
在/application/config/config.php集合中,这样的$config['base_url']
$config['base_url'] = http://localhost/Codeigniter-3.1.1/在您的视图中,请执行以下任一操作来创建<form>标记
<form method="post" action="<?= base_url('news/create'); ?>">如果您已经加载了"Form“(记录在这里),请在视图中使用这一行
<?php echo form_open('news/create'); ?> 发布于 2016-10-24 18:15:58
它由框架处理,如下所示:
<h2><?php echo $title; ?></h2>
<?php echo validation_errors(); ?>
<?php echo form_open('news/create'); ?>
<label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="text">Text</label>
<textarea name="text"></textarea><br />
<input type="submit" name="submit" value="Create news item" />
</form>
另外,当我将链接放到视图时,问题就会发生,比如:
<a href="<?php echo 'news/'.$news_item['slug']; ?>">
它没有构建正确的URL,而是沿条形条复制自己。
https://stackoverflow.com/questions/40222536
复制相似问题