Accessing file in Vendor folder cakephp - php

In cakephp how can I access a file, inside vendor folder?
I am not using app folder. I have created another project folder with same structure of app.
Should I use the same
App::import('Vendor','phpseclib0.3.6/Net/SSH2.php');
statement or anything else.

Vendors libs should follow some name conventions. For libs with custom names us the following:
App::import(
'Vendor',
'aUniqueIdentifier',
array('file' => 'phpseclib0.3.6/Net/SSH2.php')
);
And read section Loading Vendor Files

Related

Yii2 - extension structures

Recently I added a telegram bot extension in my Yii2 application to use it. but actually it is not a Yii2 extension but its a normal php namespace structured files and classes.
the name of this telegram extension is irazasyed/telegram-bot-sdk actualy its the name that added to my composer.json. I want to know how can I make some classess like this extension?
the irazasyed/telegram-bot-sdk structure is like this:
vandor >>
irazasyed
telegram-bot-sdk
composer.json
license
src
class1.php
class2.php
and the class files can be accessed from the namespace like \Telegram\Bot\Api from any controller in my application.
i want to know how can I make something like this myself.
I want this structure:
vendor >>
myCustomName
myCustomPakageName
composer.json
license
src
Class1.php
Class2.php
and access the class files from this namespace \something\somethingElse\Class1;
how can I do this?
Just add your files in a folder (or folders) in the project folder and use suggested root namespace. You don't need composer.json since you don't need to install it using composer. And you should not put it in vendor folder.
Example for basic project template:
- put everything in myCustomName folder in application root folder,
- set namespaces for each class like app\myCustomName (+ whatever subfolder you are using)
Example for advanced project template:
- put everything in myCustomName folder in selected application root folder (like frontend or common),
- set namespaces for each class like frontend\myCustomName (or common instead of frontend or whatever + whatever subfolder you are using)

Laravel project without frontend

currently I have a standard Laravel 5 proyect, eg:
Laravel Directory
app Directory
bootstrap Directory
config Directory
database Directory
public Directory
resources Directory
routes Directory
storage Directory
tests Directory
vendor Directory
what I'm trying to do is to take the public and resources folder out from the application and put it them on a different project, and in that way I'll use the laravel part only for backend purposes and the frontend parte I'll manage it on an outside project. e.g.:
Laravel Directory
app Directory
bootstrap Directory
config Directory
database Directory
routes Directory
storage Directory
tests Directory
vendor Directory
Frontend project
index.html
app folder
css folder
assets
Any recomendation or ideas to do it ?
Removing (or moving) the Public folder is not a good idea, especially due to the fact that the public/index.php file is the entrypoint for the application.
I personally use both laravel and lumen for a bunch of my REST-API's and it works great, so that thought is not at all wrong.
Just ignore the views, don't use them and don't expose them from any controller action, but rather return all data from the controllers as JSON instead.
This is easily done from the controller actions like:
public function getSomethingAction() {
return response()->json([
"some" => "property"
]);
}
// Which will produce the following json (including headers and all):
{
"some": "property"
}
I would also recommend that you group your routes under a API namespace of some sort:
Route::group(["prefix" => "api/v1"], function() {
Route::get('something'...
});
So now when you call domain.tdl/api/v1/something you will get a neat json response!

How to I move my javascript resources into a local folder?

I wrote a small app using laravel 5.2. I tried to keep all of my code in one folder located outside the app folder.
I created a folder called modules. Inside the modules folder I have a folder for vendor name. Then, inside the vendor folder, I have a module folder which contains my code.
Here is a simple folder structure
app modules/vendor name/module name/...
I managed to move my controllers, views and a route file into the module name folder.
How would I move all of the javascripts located in the public folder into my module name folder so that everything inside is in the same folder?
Additionally, I have a lot of questions about the views being in the module folder. Is it a better practice to use $this->publishes() to publish views to the resources/views folder that comes with laravel? If so what are the benefits?
https://laravel.com/docs/5.2/packages
The benefit to publishing the views is that the end user, should they want/need to, then has the option to modify the views.
As for the javascript, its completely fine to contain the javascript in your modules folders as the docs mention. You have 2 options as to how they're then used. You can either choose to publish them which moves them into the public folder, or you can include them in your build process if you use elixir/gulp, etc. See https://laravel.com/docs/5.2/packages#public-assets
Edit:
To publish assets such as javascript files (they could in theory be anything, be that images, css, etc.) use the following from your packages service provider.
public function boot()
{
$this->publishes([
__DIR__ . '/path/to/script.js' => public_path('vendor/my-package'),
__DIR___ . '/path/to/another.js' => public_path('vendor/my-package'),
]);
}
The above will move both script.js and another.js into the /public/vendor/my-package folder. Just to explain __DIR__ is a PHP 'magic' constant which gives the directory the current php file is located in and public_path() is a Laravel function which gives us the location of the /public folder as some users choose to rename this folder to their specific configuration.

Correctly locating asset file with asset library

I'm using the asset library that comes with pyrocms for my cms and I have a set up like this for my assets. I am trying to figure out with the paths and namespacing how I can access the bootstrap.css file correctly with the documentation.
http://docs.pyrocms.com/2.1/manual/developers/tools/assets
I have updated my asset.php configuration file to look like this:
$config['asset_paths'] = array(
'core' => 'assets/',
'globals' => 'assets/globals/'
);
This is the line I have set up in my template page to try and retrieve the bootstrap file:
<?php Asset::css('globals::bootstrap/css/bootstrap.min.css'); ?>
This is my file directory:
/root
/assets
/globals
/bootstrap
/css
bootstrap.css
It is saying the following error message.
Found no files matching
assets/globals/css/bootstrap/css/bootstrap.min.css
Any ideas on what I good fix would be for this?
I've never used the library in question, but judging on your post it appears that the library automatically checks for a css folder within the designated asset_path.
I would create a new asset path called bootstrap:
'bootstrap' => 'assets/globals/bootstrap/'
and add the CSS file as such:
Asset::css('bootstrap::bootstrap.min.css');

config codeigniter to run first project

I am using xampp and my document root in apache is set to htdocs directory by default. I download Codeigniter and unzip the project into this directory. It runs fine. Now I would like to use CI to create my own project. In the controllers folder I would like to create a folder named “myproject” and in the views folder of application folder, I would like to create a folder named “myproject_view” in which I will store all of my view files. My problem is I don’t know how to reset my config file (especially the route.php) for my project to work then.
CodeIgniter documentation doesn’t have a section to specify how to do this, the information given in URI Routing chapter is not enough for readers to understand this at all. Plus, What if I also would like to store my controler files in a nested folder (controllers > somefolder > someanotherfolders > etc) ? Thank you very much.
[UPDATE]
If you only leave all controller in controllers folder, and view files in the views folder, then things work out easily, what if you create a folder in teh controllers and a folder for view in the views folder. I guess you need to change your default route configuration. I would like to know HOW ?
CodeIgniter's documentation covers Sub-Folders for Controllers.
Views on the other hand, are always loaded from controllers. Therefore, you can write:
$this->load->view('my_folder_name/my_view');
Routes are not required here.

Categories