duanqiao3608 2012-11-13 17:39
浏览 37
已采纳

很难理解Codeigniter URL

This is one of those things that just makes me feel like an idjut.

Ok - so I am just starting out with Codeigniter and I just am having a hell of a time getting my head around the URL system.

Here are some relevant config settings up front ( and I'm on MAMP/localhost at the moment )

$config['base_url'] = 'http://localhost:8888/MY_SITE/';
$config['index_page'] = 'index.php';
$route['default_controller'] = "home";

My .htaccess file is blank as of now.

So I have a "home" controller, which I hit fine, and it loads my "home_view". On it I have a registration link ...

<p>Not a member yet? <a href="<?php echo site_url('registration'); ?>">Sign Up!</a></p>

This renders as the following HTML ...

<a href="http://localhost:8888/MY_SITE/index.php/registration">Sign Up!</a>

Everything fine so far. But when I click I get a "404 Page Not Found". I have a "registration.php" controller with an index method that loads a "registration_view.php".

This is what is showing in my address bar

http://localhost:8888/MY_SITE/index.php/registration 

Why do I not hit it?

My logs show ..

ERROR - 2012-11-13 18:21:12 --> 404 Page Not Found --> registration/index

.. WHY DOES FATE HATE ME SO?

  • 写回答

1条回答 默认 最新

  • dscizpq790832708 2012-11-13 17:45
    关注

    One of many possible and most close reason for 404 might be that there's no index() function in your controller. Can u post the code??

    EDIT ( Since ans got downvote ) I have to give more explanations.

    In this case possible reasons for 404 error can be -

    1. Your default controller is set home and the url on which your are getting 404 is calling registration controller.
    2. If there's no registration controller you get 404.
    3. If there's no function named as registration present in your default home controller.
    4. First arguement in URI (after index.php [if htaccess is not used to remove index.php] ) is for controller that will be called. And second argument after index.php is function that will be called from controller mentioned in first argument. In both cases, ie controller and function not present you get 404.
    5. If registration is function and it's visibility is set to private then you get 404.

    Just for note, to make URLs more readable you should include htaccess and add rules to remove index.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿