Reputation: 11466
I am building a backend page to create items in the database. My admin form page shows up but only with the title below. No form elements, Here is the code:
Here is the code Vendor\Events\Controller\Adminhtml\Post\Addevent
namespace Vendor\Events\Controller\Adminhtml\Post;
class Addevent extends \Magento\Backend\App\Action
{
protected $resultPageFactory = false;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
)
{
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('Vendor Create an Event')));
return $resultPage;
}
}
View/Adminhtml/layout/vendor_events_addevent.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<uiComponent name="vendor_events_addevent_listing"/>
</referenceContainer>
</body>
View/Adminhtml/ui_component/vendor_events_addevent_listing.xml
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_events.vendor_events_listing_data_source</item>
<item name="deps" xsi:type="string">vendor_events.vendor_events_listing_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Employee Information</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="namespace" xsi:type="string">employee_form</item>
</item>
<item name="template" xsi:type="string">templates/form/collapsible</item>
</argument>
<dataSource name="employee_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
<argument name="name" xsi:type="string">woodmizer_events_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">pri_id</argument>
<argument name="requestFieldName" xsi:type="string">pri_id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</dataSource>
<fieldset name="employee_details">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="collapsible" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Employee Details</item>
<item name="sortOrder" xsi:type="number">20</item>
</item>
</argument>
<field name="employee_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Employee Id</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">employee</item>
<item name="dataScope" xsi:type="string">employee_id</item>
</item>
</argument>
</field>
</fieldset>
Upvotes: 0
Views: 1579
Reputation: 287
Your file names are wrong. Your controller is Vendor\Events\Controller\Adminhtml\Post\Addevent
and in your etc/adminhtml
folder you should have a routes.xml
which tells Magento where the module resources are.
When Magento creates the URLs for these pages, it's looking for <route>/<folder>/<file>
which in your case is <whatever your route is>/post/addevent
. Your layout needs to be named <whatever your route is>_post_addevent.xml
and the UI component <whatever your route is>_addevent_listing.xml
. You'll need to replace <whatever your route is>
accordingly. Then as long as your models and di.xml are as they should be, (I assume they are). You can then rerun the main Magento commands and you should have a page you can view in the admin.
Magento commands wise, I would usually use setup:upgrade
and setup:di:compile
just to be on the safe side. Make sure you update the path in your layout file to match the one you use for the UI component.
Upvotes: 2