English 中文(简体)
为什么我的URL不工作?
原标题:Why does my URL redirect not work?

我下载准则Igniter 2.1.0,我接过rel=“nofollow”>tutorial

问题在于我试图以本《欧洲刑法》的形式提出:

http://localhost/CodeIgniter/index.php/news/create

the page is redirected to this URL:

http://localhost/CodeIgniter/index.php/news/localhost/CodeIgniter/index.php/news/create

我为改变路线提出了许多办法。 php,但它没有工作。 我如何确定这一点?

route.php

$route[ news/create ] =  news/create ;
$route[ news/(:any) ] =  news/view/$1 ;
$route[ news ] =  news ;
$route[ (:any) ] =  pages/view/$1 ;
$route[ default_controller ] =  pages/view ;

This is the code for the form page:

public function create()
{
    $this->load->helper( form );
    $this->load->library( form_validation );

    $data[ title ] =  Create a news item ;

    $this->form_validation->set_rules( title ,  Title ,  required );
    $this->form_validation->set_rules( text ,  text ,  required );

    if ($this->form_validation->run() === FALSE)
    {
        $this->load->view( templates/header , $data);   
        $this->load->view( news/create );
        $this->load->view( templates/footer );

    }
    else
    {
        $this->news_model->set_news();
        $this->load->view( news/success );
    }
}

I notice that when the form page when the page is loaded, below code segment will executed, however, the else segment never got changes to execute.

if ($this->form_validation->run() === FALSE)
    {
        $this->load->view( templates/header , $data);   
        $this->load->view( news/create );
        $this->load->view( templates/footer );

    }

This is the form page, nothing special, just call the create function shown above. create.php

<h2>Create a news item</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>

This is the HTML for the form page:

<html>
<head>
<title>Create a news item - CodeIgniter 2 Tutorial</title>
</head>
<body>
<h1>CodeIgniter 2 tutorial</h1><h2>Create a news item</h2>

<form action="localhost/CodeIgniter/index.php/news/create" method="post" accept-charset="utf-8">
<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><strong>&copy;2012</strong>
</body>
</html>

当我发布<条码>新项目纽吨时,URL改为

http://localhost/CodeIgniter/index.php/news/localhost/CodeIgniter/index.php/news/create

and page shows 404 Pages Not Found

最佳回答

我找到了解决办法,其起因是不适当的基轮 setting。

在我的基律之前:$config[ base_url] = localhost/CodeIgniter ;

现在我改为:

$config[ base_url ] =  http://localhost/CodeIgniter/ ;

如今,这部法律已经生效。

感谢谁努力提供帮助:

问题回答

只是建议,这可能有助于:

$config[ base_url ] = ((isset($_SERVER[ HTTPS ]) && $_SERVER[ HTTPS ] == "on") ? "https" : "http");
$config[ base_url ] .= "://".$_SERVER[ HTTP_HOST ];
$config[ base_url ] .= str_replace(basename($_SERVER[ SCRIPT_NAME ]),"",$_SERVER[ SCRIPT_NAME ]);

在您的信中提出这一点。 php文档中,你将永远不会担心<代码> config[基准_url]。 由于将设置<条码><<>>/代码>或<条码>,<条码>港、<条码>、<条码>>、>号(第8080、8880等)和<条码>密码根切/条码>。 此外,今后在您的任何编码项目中也可重新使用。

http://www.palgenep-center.com/dynamic-base-url-code-igniter.html





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签