Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 500 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you setup the controller in a Silex PHP Framework project?

#1
I can't seem to get anything to work past the root path so far:

Do you put all your controller calls in the app.php file?

$app->get('/', function ($id) {
...
});

$app->get('/about', function ($id) {
...
});

Or do you put them in separate files?
So far the root get method works fine and renders a twig template, but anything past that does nothing.
Reply

#2
Silex is a microframework. It gives you the ability to define your application within a single file. But that does not mean you have to.

What I usually do is define all the controllers in one `app.php` file, but extract re-usable parts into classes within the `src` directory, for example `src/ProjectName/SomeClass.php`, which can be autoloaded and also unit tested.

Now, if the amount of controllers grows, you can split up your application into "modules" and mount them under your main application (for example, mount an admin panel under `/admin`). Silex supports mounting, like so:

require_once __DIR__.'/silex.phar';

$app = new Silex\Application();

$app->mount('/admin', new Silex\LazyApplication(__DIR__.'/admin.php'));

For more details on mounting, check out [Reusing applications][1] from the Silex documentation.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through