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

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
