且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Codeigniter - 重定向

更新时间:2023-11-13 21:49:40

如前所述,请确保在开始之前没有空格(空格,制表符,新行等)<?php 在您的控制器。如果您有一个关闭?> 标记,那么这可以删除,因为它可能会导致 redirect

As already mentioned, make sure there is no white space (spaces, tabs, new lines etc.) before the opening <?php tag in your controller. If you have a closing ?> tag, then this can be removed, as it can often cause issues with redirect.

在这种情况下,如果您不关心在URL中包含函数的名称在URL中显示您正在调用的函数的URL( logotyp()),而 redirect )/刷新页面,那么您可以直接在 index()函数中调用相关函数:

In this case, if you aren't concerned about having the function's name in the URL (this will not change the URL to show the function that you are calling (logotyp()) in the URL, whereas the redirect function would)/refreshing the page, then you could just call the relevant function directly in your index() function:

public function index()
{
    $this->logotyp();
}






CSS不加载);它可能发生,因为到其路径的链接不正确。使用CodeIgniter的 URL Helper 中的 base_url 函数可以轻松生成正确的路径。我不知道你的CSS文件位于哪里,但对于这个例子,我将假设,相对于网站的根,它在这里: assets / css / style.css 只需添加相对于web根目录的路径:


For your second issue (CSS not loading); it is probably occuring because the link to its path is incorrect. Using the base_url function from CodeIgniter's URL Helper you can easily generate the correct path. I don't know where your CSS file(s) is located, but for this example I'll assume that, relative to the site root, it is here: assets/css/style.css. Simply add the path relative to web root as so:

<link href="<?php echo base_url("assets/css/style.css"); ?>" type="text/css" rel="stylesheet">

HTML助手中的html_helper.html#link_tagrel =nofollow> link_tag()也可以帮助生成样式表链接。

link_tag() in the HTML Helpercan also help with the generation of stylesheet links.