对于php–Magento–在Magento扩展中加载模型时出错?感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于BetterBlocks:Magento2PHPViewModels(PHP视图
对于php – Magento – 在Magento扩展中加载模型时出错?感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于Better Blocks: Magento 2 PHP View Models (PHP 视图模型让模块开发更独立)、Magento 2-购物车页面-异常#0(异常):具有相同ID“ 0”的项目(Magento Quote Model Quote Item)已经存在、Magento 2.0 Alipay Cross-Border Mobile Payment Extension - Magento 2.0 支付宝跨境支付手机版、Magento 2教程 -- Magento 中的 Areas的有用信息。
本文目录一览:- php – Magento – 在Magento扩展中加载模型时出错?
- Better Blocks: Magento 2 PHP View Models (PHP 视图模型让模块开发更独立)
- Magento 2-购物车页面-异常#0(异常):具有相同ID“ 0”的项目(Magento Quote Model Quote Item)已经存在
- Magento 2.0 Alipay Cross-Border Mobile Payment Extension - Magento 2.0 支付宝跨境支付手机版
- Magento 2教程 -- Magento 中的 Areas
php – Magento – 在Magento扩展中加载模型时出错?
我正在开发一个magento扩展,我试图在数据库表中插入值,但我遇到的问题是模型没有加载.
问题是当我在我的控制器中调用save()函数时,页面上出现一个错误:
Fatal error: Call to a member function beginTransaction() on a non-object in /var/www/magento/app/code/core/Mage/Core/Model/Abstract.PHP on line 313
当我在我的system.log文件中检查错误日志时,我看到了这个错误:
Warning: include(Gwb/Magecrmsync/Model/MysqL4/Magecrmsync.PHP): Failed to open stream: No such file or directory in /var/www/magento/lib/Varien/Autoload.PHP on line 93
我用谷歌搜索但找不到答案.请帮忙
这是我的config.xml代码:
<?xml version="1.0"?>
<config>
<!-- turn on our module, required for install support -->
<modules>
<Gwb_Magecrmsync>
<version>0.1.0</version>
</Gwb_Magecrmsync>
</modules>
<frontend>
<routers>
<magecrmsync>
<use>standard</use>
<args>
<module>Gwb_Magecrmsync</module>
<frontName>magecrmsync</frontName>
</args>
</magecrmsync>
</routers>
<layout>
<updates>
<magecrmsync>
<file>adminhtml.xml</file>
</magecrmsync>
</updates>
</layout>
</frontend>
<admin>
<routers>
<magecrmsync>
<use>admin</use>
<args>
<module>Gwb_Magecrmsync</module>
<frontName>magecrmsync</frontName>
</args>
</magecrmsync>
</routers>
</admin>
<adminhtml>
<menu>
<menu1 translate="title" module="magecrmsync">
<title>Synchronize</title>
<sort_order>999</sort_order>
<children>
<menuitem1 module="magecrmsync">
<title>Customers</title>
<action>magecrmsync/adminhtml_customers</action>
</menuitem1>
<menuitem2 module="magecrmsync">
<title>Orders</title>
<action>magecrmsync/adminhtml_orders</action>
</menuitem2>
<menuitem3 module="magecrmsync">
<title>Products</title>
<action>magecrmsync/adminhtml_products</action>
</menuitem3>
<menuitem4 module="magecrmsync">
<title>Settings</title>
<action>magecrmsync/adminhtml_settings</action>
</menuitem4>
</children>
</menu1>
</menu>
<acl>
<resources>
<admin>
<children>
<menu1 translate="title" module="magecrmsync">
<title>Synchronize</title>
<sort_order>999</sort_order>
<children>
<menuitem1>
<title>Customers</title>
</menuitem1>
<menuitem2>
<title>Orders</title>
</menuitem2>
<menuitem3>
<title>Products</title>
</menuitem3>
<menuitem4>
<title>Settings</title>
</menuitem4>
</children>
</menu1>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<!-- turn on models -->
<models>
<magecrmsync>
<class>Gwb_Magecrmsync_Model</class>
<resourceModel>Magecrmsync_MysqL4</resourceModel>
</magecrmsync>
<Magecrmsync_MysqL4>
<class>Gwb_Magecrmsync_Model_MysqL4</class>
<entities>
<magecrmsync>
<table>magecrmsync</table>
</magecrmsync>
</entities>
</Magecrmsync_MysqL4>
</models>
<!-- turn on models -->
<!-- turn on database connections -->
<resources>
<!-- setup is needed for automatic installation -->
<magecrmsync_setup>
<setup>
<module>Gwb_Magecrmsync</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</magecrmsync_setup>
<magecrmsync_write>
<connection>
<use>core_write</use>
</connection>
</magecrmsync_write>
<magecrmsync_read>
<connection>
<use>core_read</use>
</connection>
</magecrmsync_read>
</resources>
<blocks>
<magecrmsync>
<class>Gwb_Magecrmsync_Block</class>
</magecrmsync>
</blocks>
<helpers>
<magecrmsync>
<class>Gwb_Magecrmsync_Helper</class>
</magecrmsync>
</helpers>
<layout>
<magecrmsync>
<file>adminhtml.xml</file>
</magecrmsync>
</layout>
</global>
</config>
这是我的控制器文件中的函数:
public function settingsAction()
{
if($this->getRequest()->getPost())
{
try
{
$login_info = Mage::getModel('magecrmsync/magecrmsync');
$username = $this->getRequest()->getPost('username');
$password = $this->getRequest()->getPost('password');
$login_info->setUsername($username);
$login_info->setPassword(md5($password));
$login_info->save();
Mage::getSingleton('adminhtml/session')->addSuccess("Login information has been updated successfully.");
}
catch(Exception $e)
{
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
else
{
Mage::getSingleton('adminhtml/session')->addError("Error! Please try again.");
}
$this->_redirect('/*/*');
}
任何人都可以在这里找出问题,而不是让我的模型加载吗?
任何帮助将不胜感激,对我有所帮助.
提前致谢
解决方法:
经过超过24小时的研究,我终于开始工作了.由于文件夹权限,我遇到此错误(找不到文件).当我授予它工作的文件夹的权限.谢谢你的帮助.
Better Blocks: Magento 2 PHP View Models (PHP 视图模型让模块开发更独立)
Block类必须继承\Magento\Framework\View\Element\AbstractBlock,而\Magento\Framework\View\Element\AbstractBlock类又实现了\Magento\Framework\View\Element\BlockInterface。鉴于大多数Blocks需要渲染模版,所以大多数情况下他们在继承链中更进一步,继承自\Magento\Framework\View\Element\Template。
Blocks的问题
虽然Blocks可以很好的完成他们的工作,他们也有一些缺点。
所有的Blocks都使用构造注入,所以当一个Block需要额外的依赖的时候,它必须把依赖上下文变量传入parent::__construct()方法。
自然,许多开发人员然后通过受保护的getter或受保护的字段访问父项依赖项。这些定制逻辑和平台代码的交织导致代码更加复杂。 与简单的没有继承关系的类相比,代码变得难以理解和维护。
另外,当使用测试来驱动开发时,虽然依赖关系跟业务逻辑没有任何关系,但是因为必须处理父类之间的关系,使过程变得十分繁琐。 这是开发人员踏上TDD旅程的又一个障碍,并助长了难以进行测试的神话。
PHP视图模型 在写这编文章的时候我发现了以下模版block类上面的PHPDoc注释。
/** * Avoid extending this class. *
* If you need custom presentation logic in your blocks, use this class as block, and declare
* custom view models in block arguments in layout handle file.
* * Example: * * * My\Module\ViewModel\Custom\ *
* **/
此注释已添加到2.2版本中,并准确描述了Anton所指的内容。
更好的是,自Magento 2.2.1版本,我们甚至不用指定的class参数,因为是默认值。
现在我大多使用以下方式来声明我的Blocks, Example\ViewModel\Block\Example
<referenceContainer name="columns.top">
<block name="view-model-example" template="Example_ViewModel::example.phtml">
<arguments>
<argument name="view_model" xsi:type="object">Example\ViewModel\Block\Example</argument>
</arguments>
</block>
</referenceContainer>
模版是这样开始的:
<?php declare(strict_types=1);
/** @var \Example\ViewModel\Block\Example $viewModel */
$viewModel = $block->getData(''view_model'');
?>
<?php $viewModel->getSomeThing() ?>
这个视图模块必须实现标记接口,否则我们会遇到一个异常:
(UnexpectedValueException): Instance of Magento\Framework\View\Element\Block\ArgumentInterface is expected, got Example\ViewModel\Block\Example instead.
这个是异常中所指的ArgumentInterface
/** * Block argument interface.
* All objects that are injected to block arguments should implement this interface.
*/
interface ArgumentInterface { }
此限制是安全预防措施,由于布局可以在多个文件内配置--包括后台由商户添加的布局--此限制被用来限制由布局声明实例化Blocks的个数。
实际上,必须实现此接口并不是真正的麻烦。 我喜欢使用几乎解耦的视图模型,而不是从AbstractBlock扩展的块。
构造函数不需要调用 parent::__construct(),任何依赖关系都显而易见
在某些情况下,仍然需要使用自定义块。 例如,根据条件判断对模版进行渲染。 但是在大多数情况下,视图模型已经足够了。
视图模型的好处
简而言之,使用视图模型代替块可以更好地分离自定义代码和平台代码,这导致代码具有以下属性:
更容易理解
更易于维护
更可重用
更安全的升级
更容易测试
Magento 2-购物车页面-异常#0(异常):具有相同ID“ 0”的项目(Magento Quote Model Quote Item)已经存在
当表损坏或从主索引列中删除自动增量时,通常会发生这种问题。 通过“ DESCRIBE QUOTE”检查表字段,是否设置了自动增量?如果有主键集(需要唯一值),但缺少自动增量。这可能是错误的原因:相同的ID“ 0”已经存在。
Magento 2.0 Alipay Cross-Border Mobile Payment Extension - Magento 2.0 支付宝跨境支付手机版
Overview
Accept payments in Magento 2 using the Alipay Cross-border Mobile Payment Gateway. Advanced & deeply integrated by Alipaymate.com (Certified Alipay Open Platform Developer)
Detail
This extension allows you to accept payments made via the Cross-border Mobile Payment gateway of Alipay. The extension supports all of the 16 currencies, and Fully support CNY(RMB) price for checkout. It is easily installed in your shop, without having to make any changes to the source code.
Features
Use Alipay Asynchronous Notification to ensure order status consistent
Support All 16 currencies
Fully support CNY(RMB) price for checkout
Multi-currency support
No magento core code changes
100% open source
Easy installation
Comes With
Free lifetime upgrade
Free lifetime customer support
7 days money back guarantee
Get Extension
Please goto alipaymate shop to obtain detailed information of [Magento 2.0 - Alipay Cross-border Mobile Payment Extension]
About Alipaymate
Over the past three years, Alipaymate has been focused on payment module development of Magento, Opencart, Zencart, WooCommerce, ECSHOP and so on. especially good at Alipay payment, Wechat payment, Tenpay payment. And won the Certified Alipay Open Platform Developer qualification, and Certified Wechat Open Platform Developer qualification. Please contact: alipaymate@qq.com
Screenshot
Alipay Cross-border Mobile Payment Configuration
Choose Payment Methods
Place Order
Alipay Checkout Counter
Order Checkout Successfully
Order Status is Processing
Magento 2教程 -- Magento 中的 Areas
Magento 2 教程,Mageno 中的 Areas
本篇 Magento 2 教程主要给大家讲解 Magento 中的 Area 的原理是什么,在 Magento 使用到的地方都有哪些。方便大家在具体的工作中用到的时候不在犯怵,甚至是能够做到游刃有余。
更多 《Magento 2 教程》
Magento 中的 Areas
area 是一个逻辑组件,用来组织请求处理相关的代码。针对 area, 我们绝大部分时候不需要做特殊处理,但是理解 area 对于理解 Magento 相当重要。
在 Magento\Framework\App\Area 类中的 AREA_* 相关常量暗示了 area 的种类。大致有以下几种:
const AREA_GLOBAL = ''global'';
const AREA_FRONTEND = ''frontend'';
const AREA_ADMINHTML = ''adminhtml'';
const AREA_DOC = ''doc'';
const AREA_CRONTAB = ''crontab'';
const AREA_WEBAPI_REST = ''webapi_rest'';
const AREA_WEBAPI_SOAP = ''webapi_soap'';
通过在 <MAGENTO_DIR> di.xml 文件中搜索 <argument name="areas" 字符串,我们能发现至少有 5 种 area 被添加到了 Magento\Framework\App\AreaList 类的 areas 参数中
- 位于 <MAGENTOI_DIR>/module-backend/etc/di.xml 的 adminhtml
- 位于 <MAGENTOI_DIR>/module-webapi/etc/di.xml 的 webapi_rest
- 位于 <MAGENTOI_DIR>/magento/module-webapi/etc/di.xml 的 webapi_soap
- 位于 <MAGENTOI_DIR>/magento/module-store/etc/di.xml 的 frontend
- 位于 <MAGENTOI_DIR>/magento/module-cron/etc/di.xml 的 crontab
默认的 area 是 frontend, 是由 module-store/etc/di.xml 文件中的 default 参数定义的。 global area 是在缺失 adminhtml 和 frontend area 情况下的默认的 area。
看看 <MAGENTO_DIR>/module-webapi/etc/di.xml 文件中的例子。
<type name="Magento\Framework\App\AreaList">
<arguments>
<argument name="areas" xsi:type="array">
<item name="webapi_rest" xsi:type="array">
<item name="frontName" xsi:type="string">rest</item>
</item>
<item name="webapi_soap" xsi:type="array">
<item name="frontName" xsi:type="string">soap</item>
</item>
</argument>
</arguments>
</type>
frontName 有时会出现在 URL 中,name 用于在内部引用配置文件中对应的 area, Magento 中定义了不同的 area, 里面包含不同的用来处理 URL 和请求的相关代码。好处是 Magento 只用加载对应 area 下的特定代码。
更多内容参见:https://www.kancloud.cn/yuesi...
我们今天的关于php – Magento – 在Magento扩展中加载模型时出错?的分享就到这里,谢谢您的阅读,如果想了解更多关于Better Blocks: Magento 2 PHP View Models (PHP 视图模型让模块开发更独立)、Magento 2-购物车页面-异常#0(异常):具有相同ID“ 0”的项目(Magento Quote Model Quote Item)已经存在、Magento 2.0 Alipay Cross-Border Mobile Payment Extension - Magento 2.0 支付宝跨境支付手机版、Magento 2教程 -- Magento 中的 Areas的相关信息,可以在本站进行搜索。
本文标签: