Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter路由到href id_Codeigniter_Url_Hyperlink - Fatal编程技术网

Codeigniter路由到href id

Codeigniter路由到href id,codeigniter,url,hyperlink,Codeigniter,Url,Hyperlink,我做了一个单页设计,希望将somesite.com/contact发送到somesite.com/index.php#contact。我正在使用a href id和div id。但我所走的路线似乎都不起作用 示例: $route['contact']=“页面控制器/索引#联系人” $route['contact']=“基本url('contact')” 我怎样才能做到这一点 提前谢谢 您需要使用#,以便浏览器知道您要访问页面的一部分。如果您真的想删除它,您可以将其用作控制器的参数,该控制器用

我做了一个单页设计,希望将somesite.com/contact发送到somesite.com/index.php#contact。我正在使用a href id和div id。但我所走的路线似乎都不起作用

示例:

  • $route['contact']=“页面控制器/索引#联系人”

  • $route['contact']=“基本url('contact')”

我怎样才能做到这一点


提前谢谢

您需要使用
#
,以便浏览器知道您要访问页面的一部分。如果您真的想删除它,您可以将其用作控制器的参数,该控制器用于显示页面,并使用javascript在页面上查找特定id。
我不会这样做,因为每次单击链接时都会重新加载页面。(除非您也使用javascript来抑制该操作并转到相关ID。)

但是,您可以使用mod_rewrite in.htaccess从url中删除index.php。所以你的url看起来像

codeigniter的.htaccess文件如下:

<IfModule mod_rewrite.c>

    RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

重新启动发动机
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php

htaccess我的朋友,htaccess…我在htaccess方面的技能非常有限,我无法使用CI路由进行此操作?等等,我已在此页面上放置了一个contactform,当它发送时,我会看到一条消息,消息在那里,但联系人页面在底部,刷新页面在顶部。这就是为什么我想介绍index.php#contact url to/contact,这样我就可以返回到确切的页面。您可以返回到,这样您就可以到达正确的高度。否则,您将不得不使用一些javascript来达到正确的高度。您还可以在处处理表单,将消息存储在会话flash数据中,重定向到并显示消息。也许您可以使用ajax发送表单并显示消息,这样您也可以保持正确的高度。