我有一个基本模块准备好控制器和视图工作完美.现在,我正在尝试启动模型,以便在包含属性的表中使用自定义模型保存数据(问题标题,问题).基本上,为了通过模型在自定义表中保存数据,我应该采取哪些步骤?
我该怎么做,任何帮助都会有很大的帮助.
我在我的操作文件中有以下代码:
class Post extends \Magento\Framework\App\Action\Action
{
protected $_objectManager;
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
{
$this->_objectManager = $objectManager;
}
public function execute()
{
$post = $this->getRequest()->getPostValue();
$model = $this->_objectManager->create('Chirag\Mygrid\Model\Question');
$model->setData('question_title', $post['question_title']);
$model->setData('question', $post['question']);
$model->save();
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\Mygrid\Model;
class Question extends \Magento\Framework\Model\AbstractModel
{
/**
* Initialize resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('Chirag\Mygrid\Model\Resource\Question');
}
}
<?php
/**
* …Run Code Online (Sandbox Code Playgroud) 随着Magento2的Stable版本的发布,我们应该如何创建一个新模块?在Magento2稳定版中创建新模块所需的确切步骤是什么?有没有办法将Magento2 Beta模块转换为稳定版本模块?
期待听到您的想法.
这是我的代码.
$storeId = Mage::app()->getStore()->getId();
$session = Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{//how to find parent id here}
Run Code Online (Sandbox Code Playgroud)
在上面提到的评论中,我想访问该特定产品的父ID.请帮忙 ..
我一直在尝试在 Magento2 中设置一个基本模块,尽管做了所有理想的更改,但它仍然抛出 404。下面是与该模块相关的代码。我的供应商名称是Chirag,模块名称是HelloWorld。
\n\n/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/module.xml
\n\n<?xml version="1.0"?>\n<!--\n/**\n * Copyright \xc2\xa9 2015 Magento. All rights reserved.\n * See COPYING.txt for license details.\n */\n-->\n<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">\n <module name="Chirag_HelloWorld" schema_version="0.0.1" setup_version="0.0.1">\n </module>\n</config>\nRun Code Online (Sandbox Code Playgroud)\n\n/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/frontend/route.xml
\n\n<?xml version="1.0"?>\n<!--\n/**\n * Copyright \xc2\xa9 2015 Magento. All rights reserved.\n * See COPYING.txt for license details.\n */\n-->\n<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">\n <router id="standard">\n <route id="helloworld" frontName="helloworld">\n <module name="Chirag_HelloWorld" />\n </route>\n </router>\n</config>\nRun Code Online (Sandbox Code Playgroud)\n\n/var/www/html/magento2/app/code/Chirag/HelloWorld/Controller/Index/Index.php
\n\n<?php\n/**\n *\n * Copyright \xc2\xa9 2015 Magento. All rights reserved.\n …Run Code Online (Sandbox Code Playgroud)