Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Following is my folder structure
--project
|_____classes
|_____config.php
|_____classes.php
|_____project
|_____index.php
|_____dashboard.php
According to the folder structure, I have all the database configurations in config.php & I have it extended in classes.php and more classes in it.
Now when I use it in the file in dashboard.php in the project folder I have to do something like this includes("../classes/config.php");
I have read the namespace concept in PHP, I have viewed many videos but I am not able to understand the concept that how to use a namespace instead of the include(''); thing.
Can anyone provide me a demo code or source codes .zip file so that I can understand the concept to implement in the project?
Any helps appreciated. Thanks :)
A namespace is not a replacement for include or require.
You can use an autoloading strategy to load classes as required. PSR-4 is a recommended standard for this, and they have an example implementation
If you're using Composer to manage the packages in your project, you can configure it to autoload your classes
Namespace is just a virtual directory system. To use code from another physical file you have to include it, there is no other work around.
just add this line at the top of your page.
use \YOUR\NAMESPACE\HERE;
and, you are good to use that specified namespace now, but still you have to include it.
To add some automation, you can use spl_autoload_register() function to automatically include you files upon class call.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I am currently working on laravel project in visual studio code text editor. If i use laravel package classes in the code at that time i want to automatically import that class using any vs code extension. If you know any best extension for this let me know.
For example I am using Schema class in the code then class should automatically imported like use use Illuminate\Support\Facades\Schema;
Use PHP Intelephense extension by Ben Mewburn for auto importing class name and many more feature. Install from vs code editor or check it here
PHP Namespace Resolver extension for VSCode works fine for me.
PHP Intelephense is the best extension for auto import class.
consider checking this out too: https://github.com/phpactor/vscode-phpactor
I use phpactor in my day to day, code intellissense, auto imports, refactoring tools like renaming classes and thus its references, navigation options (ie, move from source to test, mother or whatever), etc
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In our company we currently do not use composer, we just download and store all libs under git.
What arguments can be given to our customers and system administrators to convince them of the need to use composer?
Our request must be substantiated enough to make a decision.
With Composer you get the following advantages:
The dependencies required by the package you are pulling in are automatically taken care by Composer itself, leaving you free to focus on the programming instead of dependency management.
When the package you are using gets a new version, a simple composer update will do everything for you without ever needing to do any file management manually.
With Composer you get a centralized autoload.php file which also be optimized for production. It loads everything you need and all you need to do is include one file. The optimized version is super fast! Simply do composer dump-autoload -o.
You can use psr-4 namespaces to load a specific path on your application and have it be included in the autoloader file. Then you can simply use the namespace and it's available application wide!
Look at the following URL for a more detailed list of features: https://getcomposer.org/doc/01-basic-usage.md
There are a lot more things you can do with Composer and it's wonderful. I highly advise that you guys use it and stop wasting time on managing packages yourself.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I just learn new Code Igniter, look for login with register and authentication so I could get user group role like admin and member and other.
I would like to know what is the best Code Igniter authentication library which fits my requirements.
Anyone could help me with this?
Thanks
Ion Auth is a simple and lightweight authentication library for the CodeIgniter framework.
Documentation is located at http://benedmunds.com/ion_auth/
Installation
Just copy the files from this package to the corresponding folder in your application folder. For example, copy Ion_auth/config/ion_auth.php to application/config/ion_auth.php
You can also copy the entire directory structure into your third_party/ folder. For example, copy everything to /application/third_party/ion_auth/
CodeIgniter Version 2 Compatibility
CodeIgniter v2 requires the class file names to be lowercase. In order to support this follow the standard installation procedures and then either rename the following files or create symlinks
models/Ion_auth_model.php => models/ion_auth_model.php
controllers/Auth.php => controllers/auth.php
Hope that helps, cheers
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm trying to follow the guid on: https://www.parse.com/apps/quickstart#parse_data/php
I complete the composer install, create the composer.json file and install the SDK as described in the guide.
The next step is a mystery to me: "Require the autoload.php file, and initialize Parse:" What does this mean? Do I create a file and put the code in it? What should the file be called? Where should it be located? How to I run it?
The "guide" doesn't explain what I'm actually supposed to do!?
It does, it's the lines of code directly below that.
require 'vendor/autoload.php';
use Parse\ParseClient;
ParseClient::initialize('APPLICATION ID', 'REST API KEY', 'MASTER KEY');
Put it wherever you want, call it whatever you want.
Are you using any other framework? Parse is only the data model, you need something like Laravel or Symphony to put your code together. The next step depends on the framework you choose. In fact, I'm sure there are bridge libraries for those frameworks that do everything for you.
To start though, you can just create an index.php file and add those lines in. This will be enough to let you test the Parse library/service.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Can you provide me the name of a good (easy-to-analyze) open-source project(-s) that use namespaces instead of PEAR file structure naming conventions?
I'm willing to start using namespaces in my project, but I don't really know how should I handle this in the best possible way, e.g.:
Autoloading class will autoload my internal classes using namespaces, but what about autoloading 3rd party modules which don't use namespaces, or namespaces mirroring its file structure? Should I create two separate classes, or handle this behaviour in a single class?
Flexible file structure - how to name namespaces there? Let's have a namespace in system/ folder like: System/Foo/Bar. But what if someone changes the name of the system/ folder into something else and the namespace will remain the same?
And so on...
PSR-0 is one the few standards we have in PHP.
There's lots of examples in the internet, here's some:
Symfony https://github.com/symfony/symfony
Composer https://github.com/composer/composer
Doctrine https://github.com/doctrine/doctrine2