Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
extreme beginner question about controller in the url
  • Hi, I did the ArsMagnaTutorials tutorials on youtube a while back and didn't have this problem so maybe I'm missing something simple or it's an issue in the latest release. I am getting back to learning fuelphp and started Phillip's tutorial at nettuts but had a problem right away. In the simple example hello.php controller when I go to the url dev.local/fuel-blog/index.php/Hello it works but not if "hello" is all lower case. I checked and tested and it doesn't seem to matter whether my controller class is Controller_Hello or Controller_hello. I also checked that the controller file name is all lower case. Is there something in fuel that I need to configure to keep it from requiring the capitalized controller in the url? Thank you
  • I do not see a reason why the URI segment should start with an uppercase letter. The router will convert it to "Controller_Hello", no matter what case the URI was in. So "HELLO" should give the same response as "hello" or "HeLLo". Do you have the same issue with the default "Welcome" controller? ( as in dev.local/fuel-blog/index.php/Welcome works, but dev.local/fuel-blog/index.php/welcome doesn't )? Also make sure you're on v1.1 for all FuelPHP components (core, app and all used packages)? Phil's tutorial requires this.
  • Hi WanWizard. Thanks for the reply. I made another app for testing called fuel-test and this time rather than deleting the welcome controller I just copied the top part of it into a new hello.php file and changed the class name and code in the action_index
    <?php
    
    
    
    /**
    
     * The Welcome Controller.
    
     *
    
     * A basic controller example.  Has examples of how to set the
    
     * response body and status.
    
     * 
    
     * @package  app
    
     * @extends  Controller
    
     */
    
    class Controller_Hello extends Controller
    
    {
    
    
    
     /**
    
      * The basic welcome message
    
      * 
    
      * @access  public
    
      * @return  Response
    
      */
    
     public function action_index()
    
     {
    
      echo "hello world!";
    
     }
    
    }
    

    Funny thing is when I go to the url I don't get the hello controller. Instead I get the hello function of the welcome controller which displays the hello view. (due to the default controller being set to "welcome" I assume) Now when I delete the welcome controller I get the same issue as before. I made a goodbye.php controller and copied over the code and it works fine upper or lower case in the url. I guess it's just the name "hello" for some reason. I thought it might have something to do with the welcome controller or the views/welcome/hello.php but the problem is still there after deleting both of those. Oh well, I'm puzzled as to why the word "hello" is a problem on my system but it's not an issue since I don't think I'll ever call a real controller "hello" :-) Thanks
  • If you don't specify a controller or a method on the URI, action_index should be called.
  • Well the problem before deleting welcome.php was that http://dev.local/fuel-test/public/index.php/hello
    actually called
    http://dev.local/fuel-test/public/index.php/welcome/hello
    instead of going to my hello.php controller's action_index.
    After deleting the welcome.php file
    http://dev.local/fuel-test/public/index.php/Hello
    works but
    http://dev.local/fuel-test/public/index.php/hello
    does not I added another method "action_saysomething" to my hello.php and called the url
    http://dev.local/fuel-test/public/index.php/Hello/saysomething It works with the upper case "Hello" but not with lower case, same as before. I made test for goodbye.php and many other random words for names and they all work fine. I'm surprised not to see anything from anyone else in the comments of the tutorial but I guess it's something weird on my system.
  • No funny rewrite rules somewhere?
  • Nope. Completely fresh download. Copied the oil, public, and fuel directories over to "fuel-test", made the hello.php controller and the problem started. Oh and no htaccess is in the www root either. I did look in the logs and I see this pop up everytime I visit the url whether I use hello or Hello
    Warning - 2011-12-19 00:05:58 --> Fuel\Core\Fuel::init - The configured locale en_US is not installed on your system. I checked and the locales package is installed on my system and en_US.UTF-8 is set as my systems locale so I don't know if this is related.
  • Hi, Maybe it come from app/config/routes.php. When you install Fuelphp, it is : <?php
    return array(
    '_root_' => 'welcome/index', // The default route
    '_404_' => 'welcome/404', // The main 404 route 'hello(/:name)?' => array('welcome/hello', 'name' => 'hello'),
    ); domain/hello or domain/index.php/hello route to welcome/hello, it meants runing action_hello function of Controller_Welcome. But you delete it, then nothing find, so go to 404 action. When you change Hello, it is not match with 'hello...', and it go standard parsing, Hello ->Controller_Hello, and no 2nd segment, so use default 'action_index', so it work well. Maybe... it is routing bug, if my reasoning is correct, or it correct when the developer think it is correct. ;) So delete 'hello.....' line, and try it.
  • And @HiroKws wins! Very well spotted! That is indeed the issue. And whether or not the router should be case sensitive, that is a very good question, I'll pass this on to Dan.
  • Ah, thanks HiroKws. I was thinking the default controller shouldn't matter if I specify another controller in the url but I'm used to basic routing in CI. I see there is basic and advanced routing in fuelphp. I removed the third line and it works now. I'm not sure if I should be seeing an error that the default controller doesn't exit since I left that part but "hello" is working now. I'm a little confused by the third line but reading up on it under advanced routing in the documentation. Thank you both :-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion