magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Problem in creating edit form container of a grid in admin Panel #967

Closed aishwaryacedcoss closed 9 years ago

aishwaryacedcoss commented 9 years ago

I have created a edit form functions some thing like this:-

namespace Excercise\Weblog\Block\Adminhtml\Blogpost;

class Edit extends \Magento\Backend\Block\Widget\Container { protected $_coreRegistry = null;

/**
 * @param \Magento\Backend\Block\Template\Context $context
 * @param \Magento\Registry $registry
 * @param array $data
 */
public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Framework\Registry $registry,
    array $data = array()
) {

    $this->_coreRegistry = $registry;
    parent::__construct($context, $data);
}
/**
 * 
 * Retrieve text for header element depending on loaded page
 *
 * @return string
 */
protected function _construct()
{

    $this->_objectId = 'blogpost_id';
    $this->_blockGroup = 'Excercise_Weblog';
    $this->_controller = 'adminhtml_blogpost';

    parent::_construct();

    $this->_updateButton('save', 'label', __('Save Post'));
    $this->_addButton(
            'saveandcontinue',
            array(
                    'label' => __('Save and Continue Edit'),
                    'class' => 'save',
                    'data_attribute' => array(
                            'mage-init' => array(
                                    'button' => array('event' => 'saveAndContinueEdit', 'target' => '#edit_form')
                            )
                    )
            ),
            -100
    );

    $this->_updateButton('delete', 'label', __('Delete Post'));
}

public function getHeaderText()
{
    if ($this->_coreRegistry->registry('blog_post')->getId()) {
        return __("Edit Post '%1'", $this->escapeHtml($this->_coreRegistry->registry('blog_post')->getTitle()));
    } else {
        return __('New Post');
    }
}

Then Error comes as:- a:4:{i:0;s:142:"Invalid method Excercise\Weblog\Block\Adminhtml\Blogpost\Edit::_updateButton(Array ( [0] => save [1] => label [2] => Save Post )

I cant understand where the Problem is existing????Please help me???,my edit controller is:-

namespace Excercise\Weblog\Controller\Adminhtml\Blogpost;

class Edit extends \Excercise\Weblog\Controller\Adminhtml\Blogpost\Index {

protected $_coreRegistry = null;

/**
 * @var \Magento\Framework\Stdlib\DateTime\Filter\Date
 */
protected $_dateFilter;

  public function execute()
   {

    $this->_title->add(__('Blog Post'));

    // 1. Get ID and create model
    $id = $this->getRequest()->getParam('id');
    $model = $this->_objectManager->create('Excercise\Weblog\Model\Blogpost');

    // 2. Initial checking
 if ($id) {
        $model->load($id);
        if (!$model->getId()) {
            $this->messageManager->addError(__('This post no longer exists.'));
            $this->_redirect('*/*/');
            return;
        }
    }

    $this->_title->add($model->getId() ? $model->getTitle() : __('New Blog Post'));

    // 3. Set entered data if was error when we do save
    $data = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true);
    if (!empty($data)) {
        $model->setData($data);
    }

    // 4. Register model to use later in blocks
    //$this->_coreRegistry->register('blog_post', $model);

    // 5. Build edit form
    $this->_initAction()->_addBreadcrumb(
            $id ? __('Edit Post') : __('New Post'),
            $id ? __('Edit Post') : __('New Post')
    );

    $this->_view->renderLayout();
}

}

tzyganu commented 9 years ago

@aishwaryacedcoss Use this instead:

$this->buttonList->update('save', 'label', __('Save Post'));

and while you are at it, change the way the save and continue button is added because you will get an error after fixing the issue above

 $this->buttonList->add(
        'save-and-continue',
        [
            'label' => __('Save and Continue Edit'),
            'class' => 'save',
            'data_attribute' => [
                'mage-init' => [
                    'button' => [
                        'event' => 'saveAndContinueEdit',
                        'target' => '#edit_form'
                    ]
                ]
            ]
        ],
        -100
    );
aishwaryacedcoss commented 9 years ago

It is saying :- undefined property: Excercise\Weblog\Block\Adminhtml\Blogpost\Edit::$buttonList in /opt/lampp/htdocs/workspace/magento2/app/code/Excercise/Weblog/Block/Adminhtml/Blogpost/Edit.php on line 39";i:1;s:10863:"#0 /opt/lampp/htdocs/workspace/magento2/app/code/Excercise/Weblog/Block/Adminhtml/Blogpost/Edit.php(39): Magento\Framework\App\ErrorHandler->handler(8, 'Undefined prope...', '/opt/lampp/htdo...', 39, Array)

tzyganu commented 9 years ago

@aishwaryacedcoss Make your block extend \Magento\Backend\Block\Widget\Form\Container because that's what the edit block is...a form container. But that's not really important, you should still be able to access the buttonList member. Since your class extends \Magento\Backend\Block\Widget\Container that has a member buttonList it should be available in the child classes. Clear the cache and var/generation just to be safe.

verklov commented 9 years ago

@aishwaryacedcoss, did advice from @tzyganu help you resolve your issue? Please let us know whether you need additional assistance from someone from the team.

aishwaryacedcoss commented 9 years ago

Sorry the dealyed reply .. yes my Problem is not resolved yet ..it is giving same error

It is saying :- undefined property: Excercise\Weblog\Block\Adminhtml\Blogpost\Edit::$buttonList in /opt/lampp/htdocs/workspace/magento2/app/code/Excercise/Weblog/Block/Adminhtml/Blogpost/Edit.php on line 39";i...

otoolec commented 9 years ago

@aishwaryacedcoss can you try calling the inherited updateButton method?

If that still doesn't work can you post your latest code so we can help further?

sshrewz commented 9 years ago

@aishwaryacedcoss, since we haven't heard back from you, we'll proceed with closing this issue. If in case you do have any updates, feel free to reach out to us by submitting a new issue.

pradeeprcs commented 9 years ago

http://magento.stackexchange.com/questions/82159/magento-2-how-to-add-grid-to-the-tab-in-customer-index-edit/87637#87637

this link help you