I have PHP example on how to use Yelp Fusion API. It uses OAuth.php file with several classes. In main example it is imported with
require_once('lib/OAuth.php');
Can I do the same in Laravel?
Or I'd better provide namespace for OAuth.php file and put it somewhere on the tree? Where to put it?
I suggest your to make a new directory inside app and call it like "Classes" and store your OAuth.php as "/app/Classes/OAuth.php".
Don't forget to put a namespace App\Classes; to top of this file.
Due to having several classes inside your file I suggest to rewrite this a bit and separate each class to file
You can use the Yelp Fusion API with any OAuth implementation. To simplify the process and maintain a clean project, you can use an OAuth package.
You can find a list of OAuth packages for composer here.
Using packages instead of custom PHP files would help to keep project clean.
If you do need to add any custom PHP files, it's recommended to create a directory within the /app directory for organization. A good directory name could be "Libraries" or "Helpers," depending on the type of content being stored.
Note that directories and files within the /app directory are automatically loaded by Composer.
Related
You know wordpress template system. I'm writing a simple script with Laravel. I'm very beginner at Laravel. I need to more than one template and it must be selectable at admin panel.
I created subfolders at views doc like that:
project/resources/views
defaulttemplate
othertemplate
othertemplate2
I keep template's doc name in the database when one is selected. I want to run the site selected template.
How to I can do it?
Firstly, Wordpress has a million lines of code and it's open source. You have to observe their codes from github repo if you have ever never implemented an templating engine as same as Wordpress or any kind of equivalent applications. It's not best practice however you can simply create a new namespace for the view from the app container.
You can boot your namespace definition on AppServiceProvider
app("view")->addNamespace("theme",base_path('themes/'.DEFAULT_TEMPLATE_FOLDER_NAME));
Within this way, you can pass different folders as a view. you have to call your view files via themes:: namespace.
Let's assume you have a default folder in the themes folder as a default template and there is index.blade.php inside of it. You have to call it as a return view('themes::index') in the controller. If DEFAULT_TEMPLATE_FOLDER_NAME changed, the themes:: namespace will point to changed destination due to App Service Provider. It's a simplest version of wordpress-like templating. For the best case, you have to observe different kind of open source projects.
I am using an third party plugin to enable payment function in my laravel project. But third party only support php. Even they have provided some sample project to show how it worked in php but I have to put those files which includes functions in somewhere in my laravel project and also give them a namespace in the beginning of the file. After I define namespace for phpqrcode.php file, QRcode class still couldn't been found.
Here is the the url where system will need to access QRcode class.
I have put external php in libraries folder:
Here is the file which contains QRcode class and other classes.
I have created a set of class files that helps to create the route configuration array. I, however, do not know where to put the source files. I browsed around a little and found some answers that suggested I put up the code in packagist and install it via composer, but my classes are relatively small. So, I wanted to ask if there is another way to do it. The files must be accessible in all the modules.
Your application code is organised into modules and lives in module/<Modulename>/src/. If the code is something you might want to reuse in other applications, then it might make more sense to have it as a standalone library that you install via. Composer.
You're code is accessibly through all the application if it is configured in the composer.json's autoload section.
Code structure in ZF is quite simple. You have your modules and in every module you have an src directory. This src directory should have its own namespace. And there you can place your custom route configurator under this namespace, like 'ModuleName\RouteConfigurator'.
But if you use this logic through multiple modules, I suggest you to create a separate module for it. In this case, after a long road, you may consider creating a separate composer package from it. But it's not necessary.
If you're not familiar with defining modules, please read the zend-modulemanager's documentation (https://docs.zendframework.com/zend-modulemanager/intro/)
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
I am trying to deploy a PHP Yii app to Orchestra (https://www.engineyard.com/products/orchestra/). The platform, like I think many cloud-based platform, doesn't allow write permissions.
I've managed to get around the 'runtime' directory that Yii requires by putting it in the system's tmp folder. However I'm stuck with the 'assets' folder. Yii requires a writable AND publicly accessible folder.
Is there a way around this?
Yii requires somewhere to put the files from within the core or modules to be publicly accessible.
If this isn't possible you might have to go through and manually grab each js/css file your going to want, place them in the folders required and use scriptMap to map these back or block them and include them yourself.
There's lots of documentation around Client Script which is what handles all this.