当前位置:  首页>> 技术小册>> 全面构建Magento2电商系统

一旦安装了Magento2,您将需要配置一些选项,并根据您的特定需要管理系统生命周期。您可以使用命令行实用程序启动Magento配置和管理。

命令行能提供的功能如下所示(部分):

  • 管理缓存
  • 管理索引
  • 配置运行定时任务
  • 编译代码
  • 设置magento运行模式
  • 更新模块
  • 发布静态文件
  • 等等…

执行命令行的方式:
在magento的安装目录下,我们会看到了个bin目录,在bin目录下有一个magento文件

  1. bin/
  2. `-- magento

因此,我们执行magento命令行输入命令:

  1. php bin/magento

输入上面这条命令,magento就会帮我们列出系统中所有可用的命令,如下示例:

  1. admin
  2. admin:user:create Creates an administrator
  3. admin:user:unlock Unlock Admin Account
  4. app
  5. app:config:dump Create dump of application
  6. app:config:import Import data from shared configuration files to appropriate data storage
  7. app:config:status Checks if config propagation requires update
  8. cache
  9. cache:clean Cleans cache type(s)
  10. cache:disable Disables cache type(s)
  11. cache:enable Enables cache type(s)
  12. cache:flush Flushes cache storage used by cache type(s)
  13. cache:status Checks cache status

每条命令后面对应该命令的描述。

以下为一个更新系统缓存的完整命令:

  1. php bin/magento cache:clean

通过上面的列表,我们就可以找到对应功能的命令,然后使用 php bin/magento command来执行任何magento中可用的命令。

示例,查看当前缓存的状态:

  1. root@8f4d6f886a05# php bin/magento cache:status
  2. Current status:
  3. config: 1
  4. layout: 1
  5. block_html: 1
  6. collections: 1
  7. reflection: 1
  8. db_ddl: 1
  9. compiled_config: 1
  10. eav: 1
  11. customer_notification: 1
  12. config_integration: 1
  13. config_integration_api: 1
  14. full_page: 1
  15. config_webservice: 1
  16. translate: 1
  17. vertex: 1

示例,使用php bin/magento indexer:reindex 命令刷新系统索引

为了提高magento的性能,magento会将一些如目录、分类等数据存到对应的索引表中,系统会优先从索引表中查询数据.当我们修改这些数据时,如果索引表中的数据没有更新,我们获取到的数据就不是最新的。

如果我们的系统配置了定时任务,这些索引数据会定时去刷新,如果我们想要立即执行,则可以手动去运行上面的命令,保证数据同步为最新的。

我们可以通过上面的图片了解到,magento系统有哪些模块的数据使用到了索引,如:

  • 一些列表页面的数据(后台列表):设计配置列表、客户列表
  • 分类下的产品
  • 产品的分类
  • 价格规则
  • 库存
  • 等等…