使用PHP/CodeIgniter上的表单按钮调用控制器的函数

Ash*_*hir 2 html php codeigniter

我正在尝试使用CodeIgniter和NetBeans在PHP中进行小型项目.我有这个HTML视图:

<div class="section section_with_padding" id="users"> 
        <h1>Users Access</h1> 
        <div class="half left">
            <h4>Log In</h4>
            <p>Log In here.</p>
            <div id="login">
                <form method="post" name="contact" action="Test/any">
                    <div class="left">
                        <label for="fullname">User Name:</label> 
                        <input name="fullname" type="text" class="required input_field" id="fullname" maxlength="30" />
                    </div>
                    <div class="right">                           
                        <label for="email">Email:</label> 
                        <input name="email" type="text" class="validate-email required input_field" id="email" maxlength="30" />
                    </div>
                    <div class="clear"></div>
                    <label for="message">Message:</label> 
                    <textarea id="message" name="message" rows="0" cols="0" class="required"></textarea>
                    <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Login" />
                </form>
            </div>
        </div>

        <div class="half right">
            <h4>Mailing Address</h4>
            <h6><strong>Company Name</strong></h6>
            680-780 Aliquam semper dignissim,<br />
            Fusce cursus turpis lacus, 16780<br />
            Sit amet tortor

            <div class="clear h20"></div>
            <div class="img_nom img_border"><span></span>
            <iframe width="360" height="240" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Central+Park,+New+York,+NY,+USA&amp;aq=1&amp;sll=35.101934,-95.712891&amp;sspn=61.425057,135.263672&amp;vpsrc=6&amp;ie=UTF8&amp;hq=&amp;hnear=Central+Park,+New+York&amp;ll=40.771133,-73.974187&amp;spn=0.057126,0.132093&amp;t=m&amp;z=14&amp;output=embed"></iframe></div>
        </div>

        <a href="#home" class="home_btn">home</a> 
        <a href="#galeria" class="page_nav_btn previous">Prev</a>
        <a href="#admin" class="page_nav_btn next">Next</a>
    </div> 
Run Code Online (Sandbox Code Playgroud)

不要介意半边div,那段代码还没有完成.我的问题是:我想在控制器内调用一个函数(控制器Test.php,函数any()).我谷歌它,发现我可以使用属性'动作'所以

action="my_controller/my_function"
Run Code Online (Sandbox Code Playgroud)

但是当我在我的代码上尝试时,我得到了一个很好的

"未找到

在此服务器上找不到请求的URL/Project/Test/any."

test.php在Project\application\controllers中

我做错了什么???

小智 5

index.php在您的控制器名称之前添加即

action = "index.php/my_controller/my_function"
Run Code Online (Sandbox Code Playgroud)

您还可以index.php通过URL重写来删除URL 中的需要:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)

如手册中所述:http://ellislab.com/codeigniter/user-guide/general/urls.html(在删除index.php文件下)