我正在尝试使用 CodeIgniter 和 NetBeans 在 PHP 中做一个小项目。我有这个 HTML View :
<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&source=s_q&hl=en&geocode=&q=Central+Park,+New+York,+NY,+USA&aq=1&sll=35.101934,-95.712891&sspn=61.425057,135.263672&vpsrc=6&ie=UTF8&hq=&hnear=Central+Park,+New+York&ll=40.771133,-73.974187&spn=0.057126,0.132093&t=m&z=14&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>
不要介意右半部分的 div,该代码尚未完成。我的问题是:我想在 Controller 中调用一个函数( Controller Test.php,函数 any())。我用谷歌搜索它,发现我可以使用属性“action”,所以
action="my_controller/my_function"
但是当我在我的代码上尝试这样做时,我得到了一个不错的结果
“未找到”
在此服务器上未找到请求的 URL/Project/Test/any。”
test.php 在 Project\application\controllers 里面
我做错了什么???
最佳答案
在您的 Controller 名称前添加 index.php
即
action = "index.php/my_controller/my_function"
您还可以通过重写 URL 来删除 URL 中对 index.php
的需要:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如手册中所述:http://ellislab.com/codeigniter/user-guide/general/urls.html (在删除 index.php 文件下)
关于php - 使用 PHP/CodeIgniter 上的表单按钮调用 Controller 的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21446895/