2

I want to use symfony routing as standalone routing for my project, I have the following structure:

 app
 |--project
 |----controller
 |------catalog
 |--------category.php
 |--config
 |----routes.yml
 |--bootstrap
 |----application.php

inside category.php I have a class named Category, that has a method named index(). The router is called from boostrap\application.php

How would can I specify the path to the category file in the routes.yml? Right now it look like below

search:
    path: /search
    defaults: { _controller: 'app\project\controller\catalog\category\category::index' }
1
  • try Use Namespaces and use a callable action e.g indexAction() Commented Dec 21, 2015 at 15:19

1 Answer 1

1

Loading files is not the responsibility of the routing component. This component is just used to match routes to functions inside a class.

If you want classes to be found, you can use two methods:

  • add an autoloader which loads the specified classes
  • Follow PSR-0 (with namespaces matching the filenames and directory structure) and use composer's classloader.

I'd suggest to use the second way. This is the standard in PHP, and you're probably already using the autoloader if you fetched the routing component trough composer.

Sign up to request clarification or add additional context in comments.

1 Comment

I am actually loading the files with PSR-4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.