Table of Contents
1、简介
2、安装&更新
3、设置
4、 后台
5、小技巧
Home Backend Development PHP Tutorial Laravel 5 高性能电子商务扩展包 -- Aimeos Laravel

Laravel 5 高性能电子商务扩展包 -- Aimeos Laravel

Jun 20, 2016 pm 12:31 PM

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",            ...        ]    }
Copy after login

然后运行更新命令:

composer update
Copy after login

注意:确保已经配置好了数据库。

接下来,需要在 config/app.php 中注册服务提供者:

return array(    'providers' => array(        ...        Aimeos\Shop\ShopServiceProvider::class,    ),);
Copy after login

最后需要执行如下Artisan命令来执行或更新Aimeos安装:

php artisan vendor:publishphp artisan migratephp artisan aimeos:setup --option=setup/default/demo:1php artisan aimeos:cache
Copy after login

在生产环境中或者你不想插入演示数据,不要带上 --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(),    ),
Copy after login

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>
Copy after login

此外,还要清除Laravel缓存文件,否则可能会因为老数据导致异常:

php artisan cache:clear
Copy after login

然后,需要在浏览器中调用目录列表: http://laravel.app/list 。

注意:默然开启了CSRF保护,但是排除了 /confirm 和 /update 路由,如果支付提供者是通过POST发送数据记得在CSRF中禁止该路由。

4、 后台

要使用后台系统,需要首先设置Laravel认证,具体认证实现请参考相应文档:

  • Laravel 5.1
  • Laravel 5.2

测试认证通过后,创建一个后台账户以便登录到后台系统:

php artisan aimeos:account  --admin
Copy after login

其中 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' );    });}
Copy after login

如果你的 ./public 目录对服务器而言不可写,需要设置其可写权限:

mkdir public/files public/preview public/uploadschmod 777 public/files public/preview public/uploads
Copy after login

注意:在生产环境中,需要更加细粒度的分配权限。

后台访问地址为: http://laravel.app/admin 。

输入新创建账户的邮箱和密码登录后,如果没有跳转到后台页面,再次访问 /admin 页面。

5、小技巧

为了简化开发,需要配置不使用内容缓存,这可以通过配置 config/shop.php 来实现:

'madmin' => array(        'cache' => array(            'manager' => array(                'name' => 'None',            ),        ),    ),
Copy after login

更多详情,请参考其官方文档: https://aimeos.org/Laravel

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

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.

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

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

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

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�...

See all articles