I am trying to use this extension https://github.com/2amigos/yii-cdn-asset-management-library in order to publish my assets to Amazon S3.
I installed it using Composer and I can confirm that the files are there. According to the documentation, the next step is to modify my Yii configuration file (I modified main.php and console.php) and put the necessary information in the components section. I already did that.
In order to publish the assets, I needed to run the following code:
./yiic S3 --manager=cdnManager publish --userVersionCache=1
However, yiic cannot seem to locate the S3Command.php file. I get no such file or directory errors because of that. Any thoughts on how to proceed?
Related
I have multiple restful apis build using yii2 framework, What i wouldlike is to use a single vendor directory stored in a different address
That is
I have an application hosted at www.example1.com and another one hosted at www.example2.com and the one i would like to contain the vendor files to be at www.example3.com so that in both example1 and example2 i only have to upload the resful folder without vendor directories
After some looking into yii2 advanced folder i have found these lines in index.php
require(__DIR__ . '/_protected/vendor/autoload.php');
require(__DIR__ . '/_protected/vendor/yiisoft/yii2/Yii.php');
Ive tried as a work around by doing
require(__DIR__ . 'http:://example1.com/pathto/_protected/vendor/autoload.php');
But the above fails, How best can i achieve this
You can't do it via HTTP.
The only solution is to create shared, NFS volume, which will be mounted on both servers as your vendor/ directory. After you will be able to use the same vendor dir for two servers.
If those two sites are deployed to the same server, it might be easier.
It is very simple .
you can just copy the vendor file into your next project and change the two lines of required file path (autoload.php & yii.php) to the correct vendor location.
the /config/web.php. add vendorPath to the config with your vendor directory.
As the vendor is moved from /var/www/html/myapp/vendor to /var/www/html/frameworks/yii2, you will find problem installing a new extension or updating the existing through composer command. To fix it, modify your composer.json (right under your project directory) by adding the vendor-dir attribute under the config section, eg:
// other settings ...
"config": {
"vendor-dir":"your path",
"process-timeout": 1800
},
// other settings ...
Also, you may find "a man-in-the-middle attack" message when either update or install the new extension (i don't know if there is a relation to the modification of composer.json but i get it several times during experiments). To fix it run composer update --dry-run. then it would ok.
This can be done: Include through http.
You need to set some php variables (allow_url_include, allow_url_fopen). And you need to get rid of __DIR__ constant in front of your php file path:
require('http://example1.com/pathto/_protected/vendor/autoload.php');
BUT
Don't do this. Really. You don't want to go through all these unsafe php setups. And you don't want to expose your vendor files to all the people in the world. If your script can access php source code via http, everyone can. Also, includes over http will be extremely slow.
The (probably) only solution
If you really want to share core php files between multiple websites, you can purchase virtual server, set up both websites on it and create one folder accessible from all websites on this server.
You don't even need virtual server, you can go with some kind of multihost service with custom folder for each website and shared folder for core (vendor) files.
I'm trying to get some code set up to use an particular company's API.
I have experience with Perl and if I need a module installed, I type cpan ModuleName and most of the time it Just Works. How does that work with PHP code of similar complexity?
The company in question have a github repository with PHP Client system to access their API, which looks much the same as a perl Module.
I can git clone it, I can download it, but then what? Do I have to install it? There are no installation instructions. Or do I just start using it? There's a composer.json file in there. Do I need to run a composer command so it can figure out and install its dependencies like a CPAN module would? Will it install into system folders or just right there in whatever directory it happens to be in? I feel like there ought be some kind of official installation process because there's a /tests/ folder in the files I downloaded.
Their example code literally starts like this:
<?php
/* #var $CompanyName \CompanyName_Api */
$CompanyName = new \CompanyName_Api();
/* do interesting stuff */
and that's it. Of course nothing works if I just do that because it doesn't know where the CompanyName_Api files are. It works if I add this:
<?php
include('/full/path/to/downloaded/files/CompanyName/src/Api.php');
is that all I need to do?
In order to install all dependencies defined in composer.json you would run the following command inside the project directory:
composer install
This will find and download the dependencies into the vendor directory and it will also generate an optimized autoloader.
To autoload your own source files you'll need to add it to the autoload section in the composer.json file:
First your need to install an PHP environment like PHP, Apache and all stuff, then you need to clone that file from the git repository or just download it, then navigate to the dir and fire the command composer install. It will install all of the dependencies required for that package. After that, run the code from the browser -- the package api code may have the auto loader file which you need to include in your current package and autoloader will do all the stuff for you. Add your folder structure and file structure so that you get a better answer on this.
first thanks for your brilliant work on Restler, I am using it for some labs at the University and so far it works like a charm, really simple and elegant framework!
I've been using Restler 3.0 RC4 successfully until I updated to RC5 today. Now I'm having problems with the HtmlFormat. Whenever I try to access any of my web services that return HtmlFormat or try to enter the API Explorer, I'm getting a HTTP 500, "Unable to create cache directory /home/xxxxxxx/public_html/concrete/api/cache/php" . Also, I see a "Warning: mkdir() [function.mkdir]: No such file or directory in /home/xxxxxxx/public_html/concrete/Restler/vendor/Luracast/Restler/Format/HtmlFormat.php on line 367" .
Do you have any idea of what could be happening? In the upgrade, I just replaced my Restler framework folder with the RC5 one, without any changes in my API itself.
I would appreciate any help. Thank you!
Most of the template formats need a cache folder to keep their compiled files so that they run efficiently
Since RC5 we create a subfolder for the template type used. Even though php templates does not need compilation Restler attempts creating php folder under the default cache location, which is cache folder located in the same folder as the index.php
In your case it is
/home/xxxxxxx/public_html/concrete/api/cache
You should update the cache folder to keep it outside the web root by adding
Defaults::$cacheDirectory = '/home/xxxxxxx/cache';
And then make sure the cache folder is writable
Then HtmlFormat will create the php/twig/blade folder depending on your template preference and add the compiled files inside
I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.
The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.