CodeIgniter Anchor错误:在此服务器上找不到URL [英] CodeIgniter Anchor error: URL not found on this server
问题描述
我已经花了好几个小时才能建立一个简单的锚点链接,但没有成功。
我的控制器是
class Welcome extends CI_Controller {
public function index()
{
$ this-> load-> view ('模板');
}
public function contact()
{
$ this-> load-> view('contact');
}
}
My template.php
view基本上是一个有
< a class =menuhref> <?php echo anchor('welcome / contact /','Contato')?> < / a>
我在views目录中有一个contact.php。
我的 config.php
是
$ config ['base_url'] ='localhost';
$ config ['index_page'] ='index.php';
加载 template.php
点击链接contato我想驱动系统到函数 contact()
,负责打开页面 contact.php
。但是,我有以下错误:
/ localhost / index.php / welcome / contact / p>
缺少什么?
base_url
config MUST 包含协议和尾部斜杠。 / p>
从 config.php
档案:
您的CodeIgniter根的URL。通常,这将是您的基本URL,
带有斜杠:http://示例。 com /
如果没有设置,CodeIgniter会猜测协议,域
$ b $
因此,您可以设置 base_url
如下,或在这种情况下,只需将其留空:
$ config ['base_url'] ='http:// localhost /';
#base_url应该是绝对的,如果你在子文件夹中安装了CI:
$ config ['base_url'] ='http:// localhost / path / to / codeigniter_folder / ';
边注:,以便使用URL辅助函数code> anchor(),首先加载助手文件: $ this-> );
(或通过 autoload.php
配置文件自动加载助手)
为什么 base_url
配置会影响 anchor $ c> function?
anchor()
函数,使用 site_url()
帮助函数来确定URL地址的超链接。
和 site_url()
本身,使用两个 base_url
和 index_page $
因此,如果您为 base_url $ c $指定了错误的值c>和/或
index_page
configs, anchor()
函数将无法正常工作。
I have been for hours to make a simple anchor link working without success.
My controller is
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('template');
}
public function contact()
{
$this->load->view('contact');
}
}
My template.php
view is basically a file with
<a class="menuhref"> <?php echo anchor('welcome/contact/','Contato')?> </a>
I also have a contact.php in the views directory.
My config.php
is
$config['base_url'] = 'localhost';
$config['index_page'] = 'index.php';
When the template.php
loads and I click in the link "contato" I would like to drive the system to the function contact()
that would be responsible to open the page contact.php
. However, I have got the following error:
"/localhost/index.php/welcome/contact" was not found on this server
What is missing?
The base_url
config MUST contains the protocol and a trailing slash as well.
From the config.php
file:
URL to your CodeIgniter root. Typically this will be your base URL,
WITH a trailing slash:http://example.com/
If this is not set then CodeIgniter will guess the protocol, domain
and path to your installation.
Hence, you could set the base_url
as follows, or in this case simply leave it blank:
$config['base_url'] = 'http://localhost/';
# base_url should be absolute, If you've installed CI in sub-folder:
$config['base_url'] = 'http://localhost/path/to/codeigniter_folder/';
Side-note: in order to use URL helper functions such as anchor()
, load the helper file at first: $this->load->helper('url');
(or load the helper automatically via autoload.php
config file).
Why does base_url
config affect anchor()
function?
anchor()
function, uses site_url()
helper function to determine the URL address of the hyperlink.
And the site_url()
itself, uses two base_url
and index_page
configs to create the URL address.
Hence if you assign a wrong value to base_url
and/or index_page
configs, the anchor()
function won't work properly.
这篇关于CodeIgniter Anchor错误:在此服务器上找不到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!