I am using laravel 4.2. I am following this basic tutorial on how to build Laravel Commands. I want to know where laravel is defining or registering the file paths to. For e.g.
use Illuminate\Console\Command;
is actually refering to the path below
vendor\laravel\framework\src\Illuminate\Console\Command.php
I am new to laravel, If you could point me to the right direction it would greatly help me.
there are two files you need to look at under app/config
one is start.php this register the basic path for the laravel source files the
base path . "/vendor/laravel/framework/src" .
the second one is app.php which provide an aliases array that correspond to the source classes and files.
for instance if you want to know where the class eloquent that your models are extending is at, you need to go to app.php see that Eloquent alias points toward 'Illuminate\Database\Eloquent\Model' and concat the path from start.php so it will be at \web\yourproject\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
config.php holds the rest of the mapping.
So I studied how it locates the file it was using. Then I found out it is using a namespace. The book called CODE BRIGHT by Dayle Rees greatly helped me in understanding how namespacing works. You can scroll down under the section called THE PRIMERS where Dayle describes how it functions. It is easy to understand! Give it a try.
Related
I've taken over management of a large complex site with multiple laravel installations of various ages. Some are in use some are only partially so for some routes (complex htaccess redirects abound).
I'm new to Laravel so this is a bit of a headache for me.
Is there an easy way to have laravel include the source path and filename of the controller, model and view it has used when rendering a view so I can find what files on the server are responsible for what 'pages' on the site?
TY
If you have a relative small site (i.e. a handfull of pages) you can visit each page with Laravel debugbar activated. In my office we use this for a while now and we are pretty positive about it. There is a special 'views' tab that enables you to see which views are included when you visit a certain page. It has some nice options, you can even view queries!
Example from our development environment with APP_DEBUG=true in the .env file:
In addition to the debugbar, you can also consider a package that shows route information for you by listing all routes that are called and showing the names of controllers, methods and request type in an other colour. We use Pretty routes since it is more convenient for us to read all 'routes' in the browser than in the terminal.
When starting from the app/ directory, the path of any of these classes is the same as the namespace they are in.
So if you have a model App\Models\User, this will be located in app/models/User.php.
As for the views, you start in the resources/views/ directory, replace dots in the view name by / and add .blade.php.
So, a view named website.index is located in resources/views/website/index.blade.php.
This is kind of an advanced answer that requires some Linux skills, but with the built in commando strace you can see which resources are opened: which php file, which database calls etc. This way you can analyze what is used when.
A very good tutorial can be found here:
https://hackernoon.com/debugging-a-php-application-with-strace-4d0ae59f880b
another great article on strace with PHP: https://ma.ttias.be/linux-application-script-debugging-with-strace/
I would also suggest to use all kind of filters and grep to filter the output to something meaningful.
I am working with an existing controller in symfony and need to use an api that I have in my vendors directory. Needless to say I am entering a pre-existent, large scale project and with minimum experience in symfony I am not too sure of how to use the vendor directory. When I have tried using "use vendor\fullcontact\sdk*********;" symfony tells me that there is no class called this in my bundle. I have looked for information on using the vendor directory but have came up dry. Any information regarding how I can start using my vendor directory would be appreciated.
Seems you are using the PHP Library for FullContact API.
This library don't use namespace so you can simply try to use it adding an initial slash to the class when you are using it. As Example:
$this->name = new \Services_FullContact_Name($apikey);
Hope this help
Sorry if I am asking a silly question here, but I have googled it a lot and couldn't find any satisfactory answer.
I have some experience with codeigniter and I am new to laravel.
I have just installed laravel and jeffrey way generator tool. I am first working on my back-end admin panel, so what I need is to create nested resources so it will map to domain.com/admin/SomeController
But while using php artisan generate:resource country --fields="name:string, status:boolean"
It is working fine. but generating controllers, models, views etc in respective root directory and controller name should also be changed to support nested controllers
I want to create all these in some meaningful directory structure
App/controllers/admin/AdminCountryController.php
App/models/admin/Country.php
App/views/admin/country/index.blade.php etc.
I also checked generator tool documentation but couldn't find these details.
So I want to know how can it be achieved using generator or I have to do it manually.
If I chosen wrong path please tell me as I am at very initial phase of my project and my application structure will depend on it.
You need to create first that directory. For example, you want a controller app/controller/admin/AdminController.php, first create the admin folder on app/controller, then you can do php artisan generate:controller admin/adminController.php.
I am not sure if this coulde be done using Resouce.
Also routing in laravel is different with routing in CI. CI depends on domain.com/controllerClass/method/args and laravel is different.
I have been suffering from this problem for several months now. There are lot of tutorials explain about how to implement your code using OOP methods. With parent classes, abstract classes, Interfaces etc.
My problem is where should I create such file structure in frameworks as Codeigniter, Laravel etc. I know only controller folder to define classes. Should I place all the interfaces and parent classes in controller folder? Please explain it's really mess for me.
This tutorial helped me understand where to put my own libraries. Give it a shot!
In Laravel 4, the file structure already exists in your /app folder.
See: http://laravelbook.com/laravel-architecture/
I have just installed CakePHP 2.1. And just see that the naming convention of its is just change lot from the older version which making me crazy.
Like it was app/controllers while now it is app/Controller same way
app/models - app/Model
app/views - app/View
I know there must be some advantage on doing this. But my problem is when I use the cake bake it is creating directory in the same old fashion i.e. controllers/models/views. Which is no more accessible from the URL & obviously will throw an error.
Is anyone there who has face the same issue ? Is there any solution that cake bake also use the same conventions ?
Any help will be appreciate. Thanks.
you can always use explicit paths:
/path/to/app_dir>..\lib\Cake\Console\cake bake
from your APP dir of the current cake project.
this is foolprove and always works with the right cake version.
I do it this way and use a shortcut on my keyboard to print this (up to "cake") on a single key stroke.
The reason for the change is to be able to better autoload files based on their kind (using App::uses('User', 'Model'); and later , when namespaces are introduced (3.0?) they can be loaded a lot more easy because you will call a class then like for example: "new \Cake\Model\User();"
About your bake problem: Make sure your environment is pointing to the correct "cake" shell file. I'm pretty sure yours is still pointing to the old 1.3 "cake" shell.