I wish to use models in my package. I've looked on laravel forums/blogs but can't find a definitive answer to this question.
Where should my models be placed and how should they be namespaced?
I know how to autoload my models etc but should the models go in:
panthro/package/src/models
and be namespaced:
panthro/package
OR be located at:
panthro/package/src/panthro/package/models
and be namespaced:
panthro/package/models
What is correct or is there another solution?
Your models can reside anywhere, as long as they can be found. However to keep things more consistent, I would advise you to put them in panthro/package/src/ (or whatever the name of your package is), since src folder is almost the equivalent to app folder in your Laravel main project.
As for namespacing, I think it's fine just keep your namespacing as consistent as possible throughout your package, which usually starts with Author\PackageName for example:
namespace Panthro\Package;
Though I'd be much more specific than naming the package name as Package.
If you take a look at laravel's plugin libraries, you can learn how they do their namespacing and folder structure too.
Example:
APIRouter - Very simple library
Intervention (Laravel) - More comprehensive and bigger codebase but still easy to follow (structural-wise)
Depending on your package, if you have many types of models, it'll be wise to add another level of namespace for your models, otherwise you don't really have to.
Related
Where is the code for Laravel's built-in validators?
I want to edit Laravel's validators after and before date formats that is used to compare the field dates.
Though this is not some code based question but I would like to answer it.
If you are looking to modify Laravel's validators after and before date formats, then consider using custom validator functions to achieve the same.
There are few reasons to it:
Though Laravel is open source and you can modify them as per your requirement, but that was required when Laravel didn't provide extension functionalities for some of it batteries.
If you change the implementation internally, then you would have to ship the entire vendor directory along with your codebase. Which is not good, there are thousands of file inside vendor directory.
Changing the implementation internally will cause confusion for fellow developers. The Laravel's documentation will say X but your own implementation will perform 'Y'.
I am new in joomla . my question is why we have to use naming conventions in joomla and which part of joomla delivered with this naming conventions ?
for example when we make a plugin we have to use the plg as a naming conventions for class name . why ?
and I am confused how this class work without make any instance of it ?
As far as I know those naming conventions have historical reasons, which I do not know exactly. They are useful to easily divide between modules, components and plugins, which are all available in Joomla!, what is different to wordpress and Drupal, where you have plugins and modules only.
The last time I have created a Joomla! component, the com_ prefix is/was needed to locate and load the source code of that component, so necessary. If that is now replaced by the autoloader and namespaces, I guess one could omit it, but to hang on to the coding standards, I would recommend to keep on using it.
I asked the same question from my friend # biswarupadhikari
If you don't follow naming convention then how joomla will be able to understand which class joomla needs to call or which file joomla needs to include
I am following a tutorial where the tutor places all of his models inside the following path app>models.
I'm not willing to do that, but he is always talking about best practices like the one I'm talking about.
So, there's any problem?
Even though Laravel is a MVC framework (Model-View-Controller), we don't see a folder called Model in L5 and above.
People often tend to add everything in a folder called Model just as to group all models together, but it's optional in L5 and above.
But yeah, it's always good to keep everything under a folder called Model in my opinion.
Laravel just doesn't bottleneck you or your project into using any one method. This is something for you (and your development team, if you're a part of one) to decide on. That is the convention behind Laravel - giving you the developer choice in the matter.
I have a bunch of projects with codeigniter that all use a user controller. The controller does login, registration, user pages, etc. It also has a collection of views and a model. All of this stuff falls under /users/* in the url routes.
It would be great if all of this stuff that I reuse in each project was in one folder so it would be easy to do version management on it alone, and so it was easy to transport from project to project.
Is there a good way to do this with codeignighter?
Note: I use "user" as an example, but there are many things that I would like to bundle up and just drop into projects, such as forums, admin, etc.
If your code is reuseable (also for others) you could roll up a spark for it, see sparks.
If your code is reuseable for you alone you may have to use the HMVC modular setup as mentioned by #Dave and #dianuj or go with git submodule which I personally haven't had too much success with.
I have been doing a lot of research on MVC and file structure. Mainly I've been looking at how to start a new layout. I have downloaded a few open source applications to take a look at file structure and how files are developed.
In the first application it was set up to use the standard way (at least the way it seems to me) of putting all the controllers, models and views each in their respective folders. This is the way that all the books say to do it.
In the second application, all folders are in a modules_core or modules folder where each controller (at least what I would assume to be controllers) are in a folder in there that contain three folders: controller, model, view.
Which of the two versions is accepted as standard and common practice? Are the two applications different because of versions of Codeigniter?
The standard of Code Igniter is to use those three folders:
Controllers
Models
Views
You can also create sub folders to better separate your files.
Searching a bit, I found that MyClientBase use something called codeigniter-modular-extensions-hmvc that is like a extension for CI.
Modular Extensions makes the CodeIgniter PHP framework modular.
Modules are groups of independent components, typically model,
controller and view, arranged in an application modules sub-directory,
that can be dropped into other CodeIgniter applications.
HMVC stands for Hierarchical Model View Controller.
I don't have experience with hmvc so I cannot tell you what is better. For the standard CI structure, try to separate well in sub-folders (controllers, views and models) related files and try to use helpers to better reuse your code when you need to use functions in more than one place.
I think MyClientBase (which seems to be far from the "standard" exemple), seems to be using HMVC more then MVC.