is it important to use the same directories for views and models - laravel

is it important to use the same directories for views controllers and models or you can be free to create files inside created folders and refer to them when needed
in Laravel MVC

Check docs Directory Structure
The default Laravel application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
I myself haven't tried doing my own folder structure. I would personally stick with the standard created by Laravel and follow that.

Related

Laravel code organization

I want to organize Laravel code into below folder structure for the sake of easy maintenance and better grouping. I do not know whether I can do this in Laravel.
app
--order
----CustomerOrder.php
----CustomerOrderController.php
----CustomerOrderService.php
--purchasing
----PurchaseOrder.php
----PurchaseOrderController.php
----PurchaseOrderService.php
Can I modify configuration files to facilitate above hierarchy?
Laravel is a MVC-based framework. The controllers and models are placed in different folders as the documents instruct:
https://laravel.com/docs/master/structure
I suggest you organize and group your project folder structure according to Laravel document. The readability and maintenance will be much easier if everyone using the same folder structure in same framework rather than the customized structure.

laravel 5.4, where to put controllers, models, views and routes?

Having gone through numerous laravel tutorials and examples, i have seen source code with controllers, models and views in very different directories.
The question is, where should they go, and how does the system (which presumably requires convention) work if they are put in a different place?
E.g. the official laravel quick-start project puts them in:
app/Http/Controllers/xxxControler.php
app/Http/routes.php
resources/views/xxx.blade.php
Cant find where it has put the models.
However, the simple laravel crud master tutorial puts them here:
app/controllers/xxxControler.php
app/models/xxx.php
app/routes.php
app/views/xxx/create.blade.php
app/views/xxx/edit.blade.php
Controllers
If you look in the 5.4 documentation here it says controllers should go in app/Http/Controllers.
If this is the case, how did the latter example work (as the controller files are in the "wrong" dir, and I assume that laravel, like grails, relies on convention over configuration)?
The latter example directories seem much more logical than the official place, as a controller has nothing to do with Http - its part of the app logic.
Models
The official documentation mentions that "models typically live in the app directory". This implies they can be put put in app/models, which is good.
views
Unfortunately, the official documentation says they have to go in resources/views. Again, this would be far more logical to have views, controllers and models all being together as sub directories of app, as per the second example above. Is it possible, and advisable, to use this logical, but unofficial structure? as a beginner, I have difficulty in finding the models, views and controllers as they are put in 3 different directory paths with no obvious logic.
routes
The official documentation says that routes should go in routes/web.php. I have not found an example project using this convention - I have seen them in app/routes.php, and app/http/routes.php. Assuming its ok to put them in random places under app, how does one configure where the routes definition files go?
For Laravel version ^5.4
Controllers should be in this directory
app/Http/Controllers/xxxController.php
Models should be in this directory
app/xxx.php
Views should be in this directory
resources/views/xxx.blade.php
Routes should be in this directory
routes/web.php // for web routes
routes/api.php // for api routes
These are all recommended places to put controllers, models, views and routes. You are free to modify everything of course!
Older versions of Laravel have different places for Controllers, Models, Views and Routes. Check the documentation where they should be.
The thing is that you must recognize the Laravel version because Laravel went through many changes between years 2011 and 2016...
That link in your question for example is from year 2013 which is very old.
And I strongly recommend you to follow the Laracasts tutorials at laracasts.com

base controller zend framework 2

I wonder if someone here can help, I am just starting with Zend Framework 2 and I am find it slightly daunting to get a project started off properly..
I am trying to create a base controller that I can be extended from. I am currently using the Zend Framework 2 skeleton application.
I have created a Resources folder in vendor/zendframework/zendframework/library. Within the the Resources folder, I have a Controllers folder which houses a BaseController.php file.
How do I get my project to autoload the BaseController in the Resources folder for it to be available through out the entire site?
Any help will be most appreciated.
Thanks
You shouldn't need to create a base controller, ZF2 already provides a number of base controllers for you, such as the RestController and the AbstractActionController
http://framework.zend.com/manual/2.0/en/modules/zend.mvc.controllers.html
If you are going to create a base controller, create you own module and put it in the vendors directory.
You should never need to go into third party modules and modify code as you should be able to inherit and extend the classes that are provided by such libraries

How to load a library from Module using codeigniter modular extensions

i need to load a library from my module using Modular Extensions
my structure like this
modules/
modules/categories/library
categories_class.php
modules/categories/controllers/
categories.php
I need to load categories library in categories controller .
any one cane help me?
I see two problems..
Problem 1
According to your question, your categories module is not organized properly. The whole purpose of HMVC is compartmentalizing of code e.x; modules. Given your present question how does that structure allow you to copy your modules folder and paste it into another app? Answer: It doesnt..
Follow the example below
It should be the following from the app root:
/application/
config
modules/
categories/
views
controllers/
categories.php
libraries/
categories_class.php
models
libraries
core
controllers
Problem 2
per the user guide: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
You must prefix the module name in front of anything referenced inside the modules folder.
e.g: $this->load->library('module/library');
or in your case: $this->load->library('categories/categories_class');
I have attempted previously to exclude the modules folder name and have never gotten it to work.
Controllers can be loaded as class variables of other controllers
using $this->load->module(’module/controller’); or simply
$this->load->module(’module’); if the controller name matches the
module name.
Any loaded module controller can then be used like a library, ie:
$this->controller->method(), but it has access to its own models and
libraries independently from the caller.
I have another perspective for this error behavior, that make me spend about 3 hours, actually I am always using combination of Uppercase and Lowercase on my custom libraries on Codeigniter.
For wiredesigz of Codeigniter HMVC, remember the libraries loader behavior as same as CI itself, always use lowercase of your library classes name instead of actual class name (Maybe combination of uppercase and lowercase)

multiple applications with codeigniter from same framework directory?

could i use one codeigniter framework directory to create multiple applications?
cause it seems that i have to have separate codeigniter folder instances for different applications. i want to be able to adjust some code in one place (classes that are universal) and every application i created with codeigniter will be affected.
with yii you could do this.
you can do this folder structure:
system
website-1 (your application)
----application
----index.php
website-2 (your application)
----application
----index.php
website-3 (your application)
----application
----index.php
move the 'codeigniter application folder' from the system and put it in one of you application folders.
copy the index.php file and paste inside your application folder.
In the index.php file:
YOu should have the following:
$system_folder = "../system";
$application_folder = "application";
Both Colin and Thorpe are correct.
Out of the box, sharing is not perfect. If you want to share libraries you have to put them in the system/libraries folder which makes upgrading that little bit more difficult and models cannot be shared at all.
To created a "shared" directory for libraries and models then you can use this MY_Loader.
could i use one codeigniter framework
directory to create multiple
applications?
Yes, you can create multiple applications with one CodeIgniter instance

Resources