Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routing
  • Hello. I have a problem with routing. I have a controller called welcome in folder called welcome.
    Controller:
    namespace Fuel\Core;
    class Controller_Welcome extends Controller
    {

        public function action_index()
        {
            echo 'Hello World';
        }
    }
    routes.php:
    <?php
    return array(
    '_root_'  => 'index/index',  // The default route
    '_404_'   => '404',    // The main 404 route
            'welcome' => 'welcome/welcome'
    );
    This doesn`t work. How to access the controller welcome?
    I have problem with understanding to route.
    If i have the same routes as in documentation:
    return array(
    'about' => 'site/about',
    'contact' => 'contact/form',
    'admin' => 'admin/login',
    );
    How to access them in http.
  • I tried but it doesn`t work.
  • HarroHarro
    Accepted Answer
    There are several things wrong with it.

    Your use the namespace "Fuel\Core", which is reserved for the framework components itself. Your App by default lives in the global namespace, so no namespace definition is needed.

    Second, if your controller lives in ./classes/controller/welcome/welcome.php, the corresponding class name must be "Controller_Welcome_Welcome". The cascading file system works by taking the path (from classes, ucfirst the folder names, and replace the directory separator by an underscore.

    If you want to namespace you App, you need to change the controller prefix in your config from "Controller_" to "\\Controller". You can then do

    namespace Controller\Welcome;
    class Welcome extends \Controller {}

    or

    namespace Controller;
    class Welcome_Welcome extends \Controller {}

Howdy, Stranger!

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

In this Discussion