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.
Related
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
I'm trying to integrate svg-editor with Laravel 4.
My current solution is to insert svg-editor.html file renamed as svg-editor.php inside my views folder and move the rest of files into the public folder. So now I've moved all the calls to js and css files into the edit view and all points to the public folder to let laravel load the needed files for svg-editor. js and css files are into assets folder and I call them with asset function:
<script>{{{ asset('/assets/js/ *original path from svg-editor* ') }}}</script>
public folder structure
app
public
vendor
svg-edit-2_6
Views folder: inside svg-edit-2_6 there's just svg-editor.php to be able to include on template with #include()
Of course this solution is messy because I've to modify all calls inside svg-editor code such as paths and URLs references. My question is if there's any way to let laravel to load this program without having to modify its params. I think could be possible to make some kind of calls froms start.php file but I could not find information about how to do this.
Could it be possible?
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.
I'm creating a weather module for an application that uses weather.com's xml service. With the license from weather.com you get a couple folders of images to use with their xml service. Is there an easy or better way to store the images in the module itself rather than the public folder of the app?
I Personaly have created a folder modules in the public folder like this:
www/htdocs/meo/public/modules
For each module i create a folder in modules folder.
/srv/www/htdocs/meo/public/modules/RandImageFrontPage/
In that folder i create 3 folders:
css,img,js
I find this is more the MVC way
Since the public folder is (or, really should be) the document root of your web server, you need to put it there. The choices are:
put the images in your module, open up your folders to the outside, making the module folder accessible (bad idea)
put the images in your module, read them and output them upon request (weird idea)
put the images in the public folder
If you put the images in something like /public/images/weater_com/* I think you still got a pretty portable/namespaced location of your images.
In a Zend Framework 1.10 application, I have a controller UsersController in a module api and in the index view of that controller I would like to reference a static asset (like a javascript file). How can I do that without putting the file in the main public?
so, we have a directory setup like this:
zfproj/
../application/modules/api/controllers/UserController.php
../application/modules/api/views/scripts/users/index.phtml
../application/modules/api/public/javascript/apimodule.js
../application/controllers/
../application/views/
../public/
I want to be able to include the apimodule.js in a view (in this case the users/index view). Ideally, this would able to be done without adding anything into zfproj/public
The intention behind this is to create a module that can be deployed into a ZF 1.10 application that is completely self-contained and does not require adding assets (like Javascript files) into the applications existing public/javascript files.
Typically all your publicly accessible assets go in public. It's meant to be the web root of your application and typically you set the DOCUMENT_ROOT of your apache virtual host to this folder. I'm not sure why you'd want to store client files (javascript, css, etc) outside the webroot. Can you elaborate more on your directory/application structure (maybe hinting at the location of the file you want to include)?
Edit
What you're asking should be possible. To make a standalone module, I think you'd just move "api" inside the primary public folder and the module would have its own bootstrap or you'd have to do something in your primary bootstrap based on the module name ("api" in this case). You'd have to modify your include paths accordingly. You'd need to add an .htaccess file to protect your code directories in this case.
../application/controllers
../public/api/controllers
../public/api/javascript/apimodule.js
../public/api/index.php
You might also create a symlink in your public folder that points to the public folder of api. So,
../public/api > ../application/modules/api/public
This would allow access to public but protect your code files. One thing I often do is check out subversion external into the public folder that just points to the public folder of the module. My CMS looks like this:
application/modules/cms
application/modules/cms/ui (public facing cms UI)
public/ui (svn:external pointing to application/modules/cms/ui)
HTH give you some ideas.