12. No More MVC
2016-01-22 17:53
190 查看
1. controller responsibility
![](http://img.blog.csdn.net/20160122172135367)
![](http://img.blog.csdn.net/20160122172927295)
![](http://img.blog.csdn.net/20160122174750842)
2.创建一个模块
2.1 配置 module.xml 文件:
2.2 在 config.php 中添加
2.3 注册 registration.php
运行命令。
3.创建控制器
![](http://img.blog.csdn.net/20160127133728427)
3.1创建配置文件
3.2 创建控制器文件
![](http://img.blog.csdn.net/20160126164405643)
![](http://img.blog.csdn.net/20160126165013209)
![](http://img.blog.csdn.net/20160126164405643)
4.创建视图
4.1创建布局文件
![](http://img.blog.csdn.net/20160126173053888)
4.2创建 block
![](http://img.blog.csdn.net/20160126173549681)
4.3创建 phtml
![](http://img.blog.csdn.net/20160126174053043)
![](http://img.blog.csdn.net/20160127155912294)
![](http://img.blog.csdn.net/20160127155918070)
![](http://img.blog.csdn.net/20160127155923013)
http://alanstorm.com/magento_2_mvvm_mvc
2.创建一个模块
2.1 配置 module.xml 文件:
app/code/Test/First/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Test_First" setup_version="2.0.0"/> </config>
2.2 在 config.php 中添加
app/etc/config.php 'Test_First' => 1,
2.3 注册 registration.php
app/code/Test/First/registration.php <?php /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Test_First', __DIR__ );
运行命令。
3.创建控制器
3.1创建配置文件
app/code/Test/First/etc/frontend/routes.xml <?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="first" frontName="first"> <module name="Test_First"/> </route> </router> </config>
3.2 创建控制器文件
<?php namespace Test\First\Controller\Hello; class World extends \Magento\Framework\App\Action\Action { public function execute() { echo "<p>wwww</p>"; var_dump(__METHOD__); } }
<?php namespace Test\First\Controller\Hello; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; class World extends \Magento\Framework\App\Action\Action { protected $pageFactory; public function __construct(Context $context,PageFactory $pageFactory) { $this->pageFactory = $pageFactory; parent::__construct($context); } public function execute() { var_dump(__METHOD__); $page_object = $this->pageFactory->create(); return $page_object; } }
4.创建视图
4.1创建布局文件
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1columns" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="content"> <block template="content.phtml" class="Test\First\Block\Main" name="test_hello_world"/> </referenceBlock> </body> </page> //注意布局,1columns显示不了
4.2创建 block
<?php namespace Test\First\Block; use Magento\Framework\View\Element\Template; class Main extends Template { protected function _prepareLayout() { } //这一段可有可无 }
4.3创建 phtml
<h1> hello,world ! </h1>
http://alanstorm.com/magento_2_mvvm_mvc
相关文章推荐
- mac gradle 安装
- CF620C - Pearls in a Row
- UIView的layoutSubviews和drawRect
- 水塘抽样
- 原型模式(prototype)
- Visual Studio Code 笔记
- python内部执行过程
- java中类,对象,方法的理解
- Zend Studio配置
- 在父菜单和子菜单在同一张表的级联怎么做啊
- Ext4.2 select 和 query 区别与联系
- android studio修改新项目package名称
- linux修改ethx
- 乘法口诀表
- LeetCode227. Basic Calculator II
- UITableView-FDTemplateLayoutCell 使用
- Ubuntu14.04安装JDK与配置环境变量
- iOS崩溃调试
- 一些前端设计相关网站收集
- 智能卡数据传输T=1传输协议