Laravel 5 高性能电子商务扩展包 -- Aimeos Laravel
1、简介
该 扩展包 将 Aimeos 电商库集成到Laravel 5中,为我们提供了多个控制器用于多层过滤、产品列表、详情页展示、搜索、购物车和支付结算流程,以及对应的页面和路由,总之,这是一整套提供完整功能的工具集。
2、安装&更新
本文档介绍的是今年4月份发布的最新版本的Aimeos Laravel,我们通过Composer来完成安装,首先更新项目根目录下的 composer.json :
"prefer-stable": true, "minimum-stability": "dev", "require": { "aimeos/aimeos-laravel": "~2016.04", ... }, "scripts": { ... "post-update-cmd": [ "php artisan vendor:publish --tag=public --force", "php artisan vendor:publish", "php artisan migrate", ... ] }
然后运行更新命令:
composer update
注意:确保已经配置好了数据库。
接下来,需要在 config/app.php 中注册服务提供者:
return array( 'providers' => array( ... Aimeos\Shop\ShopServiceProvider::class, ),);
最后需要执行如下Artisan命令来执行或更新Aimeos安装:
php artisan vendor:publishphp artisan migratephp artisan aimeos:setup --option=setup/default/demo:1php artisan aimeos:cache
在生产环境中或者你不想插入演示数据,不要带上 --option=setup/default/demo:1 选项。
在Laravel 5.1中, config/shop.php 的 routes 部分需要做如下修改(因为5.1中没有中间件组 web ):
'routes' => array( 'login' => array(), 'admin' => array('middleware' => array('auth')), 'account' => array('middleware' => array('auth')), 'default' => array(), 'confirm' => array(), 'update' => array(), ),
3、设置
想要查看所有组件并让一切正常工作起来,还需要调整Blade模板 resources/views/app.blade.php ,这里是一个使用了Bootstrap的示例:
<!DOCTYPE html><html lang="en" class="no-js"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1">@yield('aimeos_header') <title>Aimeos on Laravel</title> <link href='//fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">@yield('aimeos_styles')</head><body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle Navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Laravel</a> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li><a href="/">Home</a></li> </ul> <div class="navbar-right">@yield('aimeos_head') </div> </div> </div> </nav> <div class="col-xs-12">@yield('aimeos_nav')@yield('aimeos_stage')@yield('aimeos_body')@yield('aimeos_aside')@yield('content') </div> <!-- Scripts --> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>@yield('aimeos_scripts') </body></html>
此外,还要清除Laravel缓存文件,否则可能会因为老数据导致异常:
php artisan cache:clear
然后,需要在浏览器中调用目录列表: http://laravel.app/list 。
注意:默然开启了CSRF保护,但是排除了 /confirm 和 /update 路由,如果支付提供者是通过POST发送数据记得在CSRF中禁止该路由。
4、 后台
要使用后台系统,需要首先设置Laravel认证,具体认证实现请参考相应文档:
- Laravel 5.1
- Laravel 5.2
测试认证通过后,创建一个后台账户以便登录到后台系统:
php artisan aimeos:account --admin
其中 email 用于后台登录用户名,这个创建的账户同样也可以用于前台登录,为了保护这个新账户,命令行会要求你输入账户密码。
最后一步,你需要扩展 App\Providers\AuthServiceProvider 类的 boot() 方法,定义后台认证用户的检查:
public function boot(GateContract $gate){ // Keep the lines before $gate->define('admin', function($user) { return app( '\Aimeos\Shop\Base\Support' )->checkGroup( $user->id, 'admin' ); });}
如果你的 ./public 目录对服务器而言不可写,需要设置其可写权限:
mkdir public/files public/preview public/uploadschmod 777 public/files public/preview public/uploads
注意:在生产环境中,需要更加细粒度的分配权限。
后台访问地址为: http://laravel.app/admin 。
输入新创建账户的邮箱和密码登录后,如果没有跳转到后台页面,再次访问 /admin 页面。
5、小技巧
为了简化开发,需要配置不使用内容缓存,这可以通过配置 config/shop.php 来实现:
'madmin' => array( 'cache' => array( 'manager' => array( 'name' => 'None', ), ), ),
更多详情,请参考其官方文档: https://aimeos.org/Laravel

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
