3

I have worked on yii framework before and I had possibility to create module folder and inside this put eg: news module which was included controllers, views and module

I'm new in laravel and trying to create same thing MODULE

i tried the following inside routing

Route::get('/news','/modules/news/controllers/NewsController@index'); 

file exist but i'm getting

ReflectionException
Class /modules/news/controllers/NewsController does not exist

why ? what i'm doing wrong ?

2 Answers 2

2

The Route::get() function is looking for a (auto)loaded Class, not for a file on the disk to load, which is why you're getting these errors.

It's more Laravely (Laravelish?) to include:

  • Controllers in the /app/controllers/ directory
  • Views in /app/views/ directory
  • Models in the /app/models/ directory

And if you are starting out with Laravel, this might be the best way to get started. The autoloader knows where to look for your classes then, and everything gets handled automatically for you.

With the NewsController situated in /app/controllers/ you can do this:

// no need to start the route location with a slash:
Route::get('news', array('uses' => 'NewsController@index')); 

You can "package" up functionality using Laravel's Packages, but it would be better to check out the excellent docs and then come back with specific questions..

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

1 Comment

how access controller from modules ?
2

Put your Laravel controllers in app/controllers, since that directory gets autoloaded, and it is where Laravel expects controllers to be.

Then you can use routes like this (example straight from the docs at http://laravel.com/docs/controllers#basic-controllers)

Route::get('user/{id}', 'UserController@showProfile');

Comments

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.