I am developing modular project in laravel 5.1 using pingpong package.Which gives me the project structure as below
laravel-app/
app/
bootstrap/
vendor/
modules/
├── Blog/
├── Assets/
├── Config/
├── Console/
├── Database/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── routes.php
├── Providers/
├── BlogServiceProvider.php
├── Resources/
├── lang/
├── views/
├── Repositories/
├── Tests/
├── composer.json
├── module.json
├── start.php
I want to separate this modules folders in "admin" and "client" for differentiate my client and admin side like below,
laravel-app/
app/
bootstrap/
vendor/
modules/
├── Admin/
├── Blog/
├── Assets/
├── Config/
├── Console/
├── Database/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── routes.php
├── Providers/
├── BlogServiceProvider.php
├── Resources/
├── lang/
├── views/
├── Repositories/
├── Tests/
├── composer.json
├── module.json
├── start.php
├── Client/
├── Blog/
├── Assets/
├── Config/
├── Console/
├── Database/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── routes.php
├── Providers/
├── BlogServiceProvider.php
├── Resources/
├── lang/
├── views/
├── Repositories/
├── Tests/
├── composer.json
├── module.json
├── start.php
please help me out for this,
Thanks.
UPDATE:
You can mostly achieve what you are looking for by adjusting the config/modules.php file, but you will have to switch it back and forth when switching between Admin and Client.
For example:
To generate (module:make) or use (module:use) modules within the Admin portion of your project, you will need to do the following:
In the config/modules.php file, adjust the namespace to
/*
|--------------------------------------------------------------------------
| Module Namespace
|--------------------------------------------------------------------------
|
| Default module namespace.
|
*/
'namespace' => 'Modules\Admin',
In the same file, adjust the base_path to
/*
|--------------------------------------------------------------------------
| Modules path
|--------------------------------------------------------------------------
|
| This path used for save the generated module. This path also will added
| automatically to list of scanned folders.
|
*/
'modules' => base_path('modules/admin'),
That is all you need to do and calling php artisan module:make blog will create a Blog module within modules/admin.
If you need to switch between the Admin and the Client portion of your project, you will need to adjust the same two lines within the config/modules.php file to reflect as such.
There is one more caveat:
If you are planning to use the Assets folder within your modules, you will need to also adjust the corresponding line within the config/modules.php file, AND you will need to manually adjust a couple of methods with file paths explicitly written within your module's service provider (ex: Admin/Blog/Providers/BlogServiceProvider.php), AND you will need to fix your config/view.php - just follow the comments.
P.S. you can probably create a custom command to automate switching between Admin and Client.
Related
I am implementing versioning in Laravel. Now my doubt is, where should I create the V1 subfolders within the various main folders? For example, is it okay for controllers (Controllers/Api/V1) but what about Models, Resources, Request, Services etc...?
There is a very well maintained package specifically for what you are trying to do, called Laravel Modules: https://github.com/nWidart/laravel-modules
You can accomplish subversions of the application inside of it, and everything like "Models, Resource, Routes, etc.." is packaged seperately from one module to another.
Modules/
├── Blog/
├── Config/
├── Console/
├── Database/
├── factories/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── Providers/
├── PostsServiceProvider.php
├── RouteServiceProvider.php
├── Resources/
├── assets/
├── lang/
├── views/
├── Routes/
├── api.php
├── web.php
├── Tests/
├── composer.json
├── module.json
├── package.json
├── webpack.mix.js
Check the documentation on how to use it: https://docs.laravelmodules.com/v9/creating-a-module
Also laravel-daily made a video on what it is here: https://www.youtube.com/watch?v=RVApkrYMcAg
I have two Laravel applications with one domain. Let say the domain is mydomain.com.
I want those two applications can be accessed via the following urls:
mydomain.com/firstapp
mydomain.com/secondapp
To realize this, this is what I have done.
configured Apache so that the starting directory is /var/www/html/
<VirtualHost *:80>
DocumentRoot "/var/www/html/"
ServerName mydomain.com
</VirtualHost>
Then I put the first app source code in the /var/www/html/firstapp directory, and the second app in the /var/html/secondapp directory.
The directory structure became like this:
var
└── www
└── html
├── firstapp
│ ├── app
│ ├── bootstrap
│ ├── config
│ ├── database
│ ├── ...
│ ├── index.php
│ └── .htaccess
└── secondapp
├── app
├── bootstrap
├── config
├── database
├── ...
├── index.php
└── .htaccess
Finally, I moved the index.php and .htaccess from the corresponding public folder in the root directory of each Laravel app and modified the corresponding path in those index.php files.
So far, it is working as I expected, but I am worried about the security.
Can anyone explain to me the right way to do it.
Note: I am using Centos 7 in the server.
I have just got Slim PHP Framework with composer. Can anyone suggest me how to use Controller and Model in slim framework. And Where to put controllers and model in slim framework.Actually I want to use slim framework only for API. And I want to use controller for it. I have read its document but I am not able to find regarding controller and models.
Slim doesn't enforce any particular layout for your application.
I tend to like to separate out PHP source from HTML templates, so I use this pattern (taken from slim-bookshelf):
app/
├── src
│ ├── Bookshelf
│ │ ├── Author.php
│ │ ├── AuthorController.php
│ │ ├── Book.php
│ │ ├── BookController.php
│ │ └── TwigExtension.php
│ ├── dependencies.php
│ ├── middleware.php
│ └── routes.php
├── templates
│ ├── bookshelf
│ │ ├── author
│ │ │ ├── books.twig
│ │ │ ├── edit.twig
│ │ │ └── list.twig
│ │ └── book
│ │ └── list.twig
│ └── layout.twig
└── settings.php
However, my APIs do not have templates, so I move everything up a level. This example comes from slim-bookshelf-api and uses a separate class for each route's action rather than a controller class:
src
├── App
│ └── Action
│ ├── HomeAction.php
│ └── PingAction.php
├── Bookshelf
│ ├── Action
│ │ ├── CreateAuthorAction.php
│ │ ├── DeleteAuthorAction.php
│ │ ├── EditAuthorAction.php
│ │ ├── GetAuthorAction.php
│ │ └── ListAuthorsAction.php
│ ├── Author.php
│ ├── AuthorMapper.php
│ └── AuthorTransformer.php
├── dependencies.php
├── middleware.php
├── routes.php
└── settings.php
New to CI, so it's probably safe to assume misunderstandings...
My folder structure looks like
.
└── www
├── appthing
│ └── V5
│ ├── application
│ │ ├── config
│ │ ├── controllers
│ │ │ ├── api
│ │ │ └── V1
│ │ │ ├── settings.php
│ │ ├── ...
│ │ └── views
│ └── system
└── vhosts
└── appthing
index.php
.htaccess
htaccess
My apache config in /etc/apache2/sites-available/000-default.conf looks like:
DocumentRoot /var/www/www/vhosts/appthing
<Directory "/var/www/www/vhosts/appthing">
AllowOverride All
</Directory>
When I navigate to ipaddress/index.php I get an authentication error, which is good, since I can at least access the index.php file. However, if I try to go to index.php/settings I get a CI 404 error. The same code works on my computer (OS X, trying to put it on a AWS Ubuntu 16 instance currently), so it's not a problem with CI semantics.
I think you need to set your Documentroot to /var/www/www/appthing/V5. Normally you should have and index.php file in your CI project which will redirect you to a home (standard = welcome.php) controller.
I'm quite new to both Zend and QUnit and I've got a bit stuck when it comes to setting up my QUnit tests to test my JavaScript.
I'm trying to test to some DOM manipulation and I understand that I have to put the html I'm testing against inside a #qunit-fixture div in my Qunit test file. However I've got a partial view helper used in my main Zend application (works fine in my view scripts) which I just want to echo out rather than having to rewrite the html used in the helper itself (to avoid duplication). The JavaScript I am attempting to test is used in the partial view helper hence wanting to use it.
Here's the folder structure for my application with just the important files and a few others remaining:
├── application
│ ├── Bootstrap.php
│ ├── configs
│ ├── controllers
│ ├── layouts
│ │ └── scripts
│ ├── models
│ ├── plugins
│ └── views
│ ├── helpers
│ └── scripts
│ ├── error
│ ├── index
│ └── partials
│ └── partialViewHelperIWantToUse.phtml
├── docs
├── features
├── Gemfile
├── Gemfile.lock
├── js-tests
│ ├── qunitTestFile.html
│ └── vendor
│ └── qunit
│ ├── qunit.css
│ └── qunit.js
├── library
│ ├── Custom
├── public
│ ├── css
│ ├── img
│ ├── index.php
│ └── js
│ ├── jquery
│ │ └── jquery-1.7.2.min.js
│ └── javaScriptIWantToTest.js
├── Rakefile
├── tasks
└── tests
├── application
│ ├── controllers
│ └── models
├── bootstrap.php
├── library
│ └── Custom
└── phpunit.xml
I want to do something like this in my qunitTestFile.html (found in js-tests)
<div id="qunit-fixture">
<?php echo $view->partial('partialViewHelperIWantToUse.phtml') ?>
</div>
but it currently doesn't work. Renaming the qunitTestFile to have a .phtml extension causes nothing to echo out but the error "call to a member function partial() on a non-object" appears in the apache error log (I expected that but it was a simple thing to try!). I have a hunch that I might need to create another bootstrap file or something but both and Zend and Qunit are new to me so I'm a bit lost. =)
I hope that's clear and I've given enough information but let me know if it isn't.
Thanks!
Since I do not exactly know which Zend version you use, I am not sure if this helps you:
The partial()-Function is a helper of your view. Since a View .phtml File is called in a Zend_View-Context (if you use an Controller-Action to show the View) you should use
$this->partial('...');
You can setup a Zend_View for yourself, but according your directory structure, I assume you use an MVC-Pattern.