0

I have a problem adding a new field to Megaplaza_Blog Post.

I've modified UpgradeSchema to modify DB and add a new column. Column was created successfully.

I've added some code to

/app/code/Mageplaza/Blog/Block/Adminhtml/Post/Edit/Tab/Post.php

    $fieldset->addField(
        'name2',
        'text',
        [
            'name2'  => 'name2',
            'label' => __('Short Title (athletes)'),
            'title' => __('Short Title (athletes)'),
            'note' => __('Short Title (athletes)'),
        ]
    );

In admin>Megaplaza>Post>Edit I can see the value of this column from database in Input field. When I try to save, $fieldset is being rested and every thing from modified code is gone, and i'm getting (from

app/code/Mageplaza/Blog/Controller/Adminhtml/Post/Save.php

`

$data = $this->getRequest()->getPost('post');
print_r($data);die();

Array ( [short_description] =>short dec2[post_content] =>123[store_ids] => Array ( [0] => 1 ) [image] => Array ( [value] => /1/4/14851838971112.png ) [enabled] => 1 [in_rss] => 1 [allow_comment] => 1 [url_key] => qrq2341-123 [meta_title] => [meta_description] => [meta_keywords] => [meta_robots] => INDEX,FOLLOW [categories_ids] => Array ( [0] => 6 [1] => 8 ) )

Correct output should be like this

Array ( [post_id] => 11 [author_id] => 1 [name] => abcdef123 [name2] => 123123 [short_description] =>short dec2[post_content] =>123 [store_ids] => Array ( [0] => 1 ) [image] => Array ( [value] => /1/4/14851838971112.png ) [enabled] => 1 [in_rss] => 1 [allow_comment] => 1 [url_key] => qrq2341-123 [meta_title] => [meta_description] => [meta_keywords] => [meta_robots] => INDEX,FOLLOW [categories_ids] => Array ( [0] => 6 [1] => 8 ) )
0

I had an error in 'name2' => 'name2', should be 'name' => 'name2',.

Now i can't display Name2 on front end side by $_post->getName2().

but when i do print_r($_post->debug()); i'm getting [name2],

Array([post_id] => 2 [name] => test2 wef 243 fef [name2] => 1234nazwa211245 [short_description] => wefwef[post_content] => aefwef 
[store_ids] => 1
[enabled] => 1
[url_key] => test2-12
[in_rss] => 1
[allow_comment] => 1
[meta_robots] => INDEX,FOLLOW
[created_at] => 2017-05-19 10:20:00
[updated_at] => 2017-05-29 11:27:10
[author_id] => 1
[modifier_id] => 1
[topic_ids] => Array()

)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.