Sylius - How to add a custom promotion action? - sylius

I have followed the tutorial listed [enter link description here.
However, when i try to add a promotion with this action, i get this error:
Could not load type "AppBundle\Promotion\Action\CheapestProductDiscountPromotionActionCommand"
Upon further investigation, CheapestProductDiscountPromotionActionCommand.php goes through the following code block in FormRegistry.php:
if (class_exists($name) && in_array('Symfony\Component\Form\FormTypeInterface', class_implements($name))) {
$type = new $name();
} else {
throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name));
}
From what i can gather, it is checking if CheapestProductDiscountPromotionActionCommand.php implements FormTypeInterface but Im not entirely sure why? I thought CheapestProductDiscountConfigurationType extends AbstractType which implements FormTypeInterface? Maybe Im wrong but i would of thought that CheapestProductDiscountPromotionActionCommand.php should not be going through the above code block?
My stack trace is as follows:
Stack Trace
in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 87 +
at FormRegistry ->getType ('AppBundle\\Promotion\\Action\\CheapestProductDiscountPromotionActionCommand')
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 83 +
at FormFactory ->createNamedBuilder ('UK_WEB', 'AppBundle\\Promotion\\Action\\CheapestProductDiscountPromotionActionCommand', array(), array('auto_initialize' => false, 'label' => 'UK Web Store', 'currency' => 'GBP'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 47 +
at FormFactory ->createNamed ('UK_WEB', 'AppBundle\\Promotion\\Action\\CheapestProductDiscountPromotionActionCommand', array(), array('auto_initialize' => false, 'label' => 'UK Web Store', 'currency' => 'GBP'))
in vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/BuildChannelBasedPromotionActionFormSubscriber.php at line 114 +
at BuildChannelBasedPromotionActionFormSubscriber ->createConfigurationFieldForChannel (object(Channel), 'AppBundle\\Promotion\\Action\\CheapestProductDiscountPromotionActionCommand', array())
in vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/BuildChannelBasedPromotionActionFormSubscriber.php at line 74 +
at BuildChannelBasedPromotionActionFormSubscriber ->addConfigurationFields (object(Form), 'cheapest_product_discount', array())
in vendor/sylius/sylius/src/Sylius/Bundle/PromotionBundle/Form/EventListener/AbstractConfigurationSubscriber.php at line 72 +
at AbstractConfigurationSubscriber ->preSetData (object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
at call_user_func (array(object(BuildChannelBasedPromotionActionFormSubscriber), 'preSetData'), object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
in vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php at line 174 +
at EventDispatcher ->doDispatch (array(array(object(BuildChannelBasedPromotionActionFormSubscriber), 'preSetData')), 'form.pre_set_data', object(FormEvent))
in vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php at line 43 +
at EventDispatcher ->dispatch ('form.pre_set_data', object(FormEvent))
in vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php at line 43 +
at ImmutableEventDispatcher ->dispatch ('form.pre_set_data', object(FormEvent))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 341 +
at Form ->setData (null)
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 477 +
at Form ->initialize ()
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 226 +
at FormBuilder ->getForm ()
in vendor/sylius/sylius/src/Sylius/Bundle/PromotionBundle/Form/Type/Core/AbstractConfigurationCollectionType.php at line 54 +
at AbstractConfigurationCollectionType ->buildForm (object(FormBuilder), array('block_name' => null, 'disabled' => false, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'required' => true, 'property_path' => null, 'mapped' => true, 'by_reference' => false, 'inherit_data' => false, 'compound' => true, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_token_manager' => object(CsrfTokenManager), 'csrf_token_id' => null, 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_data' => null, 'prototype_name' => '__name__', 'entry_type' => 'Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionActionType', 'delete_empty' => false, 'button_delete_label' => 'sylius.form.collection.delete', 'label' => 'sylius.form.promotion.actions', 'attr' => array(), 'data_class' => null, 'empty_data' => object(Closure), 'error_bubbling' => true, 'label_attr' => array(), 'upload_max_size_message' => object(Closure), 'validation_groups' => null, 'constraints' => array(), 'entry_options' => array('block_name' => 'entry'), 'button_add_label' => 'sylius.form.promotion.add_action'))
in vendor/symfony/symfony/src/Symfony/Component/Form/ResolvedFormType.php at line 126 +
at ResolvedFormType ->buildForm (object(FormBuilder), array('block_name' => null, 'disabled' => false, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'required' => true, 'property_path' => null, 'mapped' => true, 'by_reference' => false, 'inherit_data' => false, 'compound' => true, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_token_manager' => object(CsrfTokenManager), 'csrf_token_id' => null, 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_data' => null, 'prototype_name' => '__name__', 'entry_type' => 'Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionActionType', 'delete_empty' => false, 'button_delete_label' => 'sylius.form.collection.delete', 'label' => 'sylius.form.promotion.actions', 'attr' => array(), 'data_class' => null, 'empty_data' => object(Closure), 'error_bubbling' => true, 'label_attr' => array(), 'upload_max_size_message' => object(Closure), 'validation_groups' => null, 'constraints' => array(), 'entry_options' => array('block_name' => 'entry'), 'button_add_label' => 'sylius.form.promotion.add_action'))
in vendor/symfony/symfony/src/Symfony/Component/Form/Extension/DataCollector/Proxy/ResolvedTypeDataCollectorProxy.php at line 102 +
at ResolvedTypeDataCollectorProxy ->buildForm (object(FormBuilder), array('block_name' => null, 'disabled' => false, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'required' => true, 'property_path' => null, 'mapped' => true, 'by_reference' => false, 'inherit_data' => false, 'compound' => true, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_token_manager' => object(CsrfTokenManager), 'csrf_token_id' => null, 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_data' => null, 'prototype_name' => '__name__', 'entry_type' => 'Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionActionType', 'delete_empty' => false, 'button_delete_label' => 'sylius.form.collection.delete', 'label' => 'sylius.form.promotion.actions', 'attr' => array(), 'data_class' => null, 'empty_data' => object(Closure), 'error_bubbling' => true, 'label_attr' => array(), 'upload_max_size_message' => object(Closure), 'validation_groups' => null, 'constraints' => array(), 'entry_options' => array('block_name' => 'entry'), 'button_add_label' => 'sylius.form.promotion.add_action'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 89 +
at FormFactory ->createNamedBuilder ('actions', 'Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionActionCollectionType', null, array('label' => 'sylius.form.promotion.actions', 'button_add_label' => 'sylius.form.promotion.add_action'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 106 +
at FormBuilder ->create ('actions', 'Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionActionCollectionType', array('label' => 'sylius.form.promotion.actions', 'button_add_label' => 'sylius.form.promotion.add_action'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 269 +
at FormBuilder ->resolveChildren ()
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 215 +
at FormBuilder ->getForm ()
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 39 +
at FormFactory ->create ('Sylius\\Bundle\\PromotionBundle\\Form\\Type\\PromotionType', object(Promotion), array())
in vendor/sylius/sylius/src/Sylius/Bundle/ResourceBundle/Controller/ResourceFormFactory.php at line 44 +
at ResourceFormFactory ->create (object(RequestConfiguration), object(Promotion))
in vendor/sylius/sylius/src/Sylius/Bundle/ResourceBundle/Controller/ResourceController.php at line 245 +
at ResourceController ->createAction (object(Request))
at call_user_func_array (array(object(ResourceController), 'createAction'), array(object(Request)))
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php at line 153 +
at HttpKernel ->handleRaw (object(Request), 1)
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php at line 68 +
at HttpKernel ->handle (object(Request), 1, true)
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php at line 168 +
at Kernel ->handle (object(Request))
in web/app_dev.php at line 43 +
at require ('/Users/camerona/Documents/Projects/CheshireRaw/web/app_dev.php')
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php at line 40 +

I found the issue in CheapestProductDiscountPromotionActionCommand.
In the sylius documentation listed here:
/**
* {#inheritdoc}
*/
public function getConfigurationFormType()
{
return CheapestProductDiscountPromotionActionCommand::class;
}
However this should be:
/**
* {#inheritdoc}
*/
public function getConfigurationFormType()
{
return CheapestProductDiscountConfigurationType::class;
}
This is why the code checked that CheapestProductDiscountPromotionActionCommand.php implements FormTypeInterface.
Ive managed to add my custom action and its working perfectly. There is a couple of issues with the sylius documentation but the implementation works :).

Related

Error message : Unknown column 'a.id_configuration' in 'order clause'

With this code i would like print a tab with some fields in prestashop back office. But i got an error message: : Unknown column 'a.id_configuration' in 'order clause'
<?php
public function __construct()
{
parent::__construct();
$this->table = 'order_invoice'; // SQL table name, will be prefixed with _DB_PREFIX_
$this->className = 'OrderInvoice'; // PHP class name
$this->allow_export = true; // allow export in CSV, XLS..
$this->fields_list = [
'id_order_invoice' => ['title' => $this->trans('ID', [], 'Admin.Global'),'class' => 'fixed-width-xs'],
'number' => ['title' => $this->trans('Number', [], 'Admin.Global'),'class' => 'fixed-width-xs'],
'date_add' => ['title' => $this->trans('Date', [], 'Admin.Global'), 'type'=>'datetime'],
'total_products_wt' => ['title' => $this->trans('Total products', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
'total_shipping_tax_incl' => ['title' => $this->trans('Total shipping', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
'total_paid_tax_incl' => ['title' => $this->trans('Total paid', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
];
}
?>
```
Since it states it's an error within the order clause (ORDER BY), we'd edit the orderBy variable like this:
$this->_orderBy = 'id_order_invoice';
You can also edit the identifier since it seems to be using the wrong identifier to begin with:
$this->identifier = 'id_order_invoice';
Hope this helps.

Redirect user after saving data in admin controller Prestashop

I have an admin controller which displays the list of data on clicking edit on an entry or adding a new entry I am showing renderForm() but after saving the data (either by edit or add) I want to redirect the user to another controller in place of showing the same controller list.
Bellow is the code which I am currently using for example of my requirements I trying to do something which I have done below in initcontent() but that is not working so I want to know where should I call this in place of initcontent()
<?php
/**
* The file is controller. Do not modify the file if you want to upgrade the module in future
*
* #author Globo Jsc <contact#globosoftware.net>
* #copyright 2016 Globo., Jsc
* #link http://www.globosoftware.net
* #license please read license in file license.txt
*/
include_once(_PS_MODULE_DIR_ . 'cardelivery/classes/AdditionalServicesModel.php');
class AdminAdditionalServiceController extends ModuleAdminControllerCore {
public $name;
public function __construct() {
$this->name = 'AdminAdditionalService';
$this->className = 'AdditionalServicesModel';
$this->table = 'additional_service';
$this->meta_title = $this->l('Additional Services');
$this->deleted = false;
$this->explicitSelect = true;
$this->context = Context::getContext();
$this->bootstrap = true;
$this->_defaultOrderBy = 'id_additional_service';
$this->filter = true;
if (Shop::isFeatureActive()) {
Shop::addTableAssociation($this->table, array('type' => 'shop'));
}
$this->position_identifier = 'id_additional_service';
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->fields_list = array(
'id_additional_service' => array(
'title' => $this->l('ID'),
'type' => 'int',
'width' => 'auto',
'orderby' => false),
'service_name' => array(
'title' => $this->l('Icon'),
'width' => 'auto',
'orderby' => false,
),
'service_desc' => array(
'title' => $this->l('service_desc'),
'type' => 'text'
),
'active' => array(
'title' => $this->l('Status'),
'width' => 'auto',
'active' => 'status',
'type' => 'bool',
'orderby' => false),
);
parent::__construct();
}
function initContent() {
parent::initContent();
if (Tools::isSubmit('submit')) {
Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminCategories') . '&conf=7');
}
}
public function initPageHeaderToolbar() {
$this->page_header_toolbar_btn['back_to_list'] = array(
'href' => Context::getContext()->link->getAdminLink('AdminGCardeliverycity', true),
'desc' => $this->l('Back to list', null, null, false),
'icon' => 'process-icon-back'
);
parent::initPageHeaderToolbar();
}
public function renderForm() {
$id_citydelivery = (int) Tools::getValue('id_citydelivery');
if ($id_citydelivery == 0) {
$addSerModObj = new AdditionalServicesModel((int) Tools::getValue('id_additional_service'));
$id_citydelivery = $addSerModObj->id_citydelivery;
}
$fields_form_1 = array(
'form' => array(
'legend' => array('title' => $this->l('Additional Service'), 'icon' => 'icon-cogs'),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_citydelivery'
),
array(
'type' => 'text',
'label' => $this->l('Service_name'),
'name' => 'service_name',
'size' => 255,
'required' => true,
'desc' => $this->l('Enter name of Arrival port')
),
array(
'type' => 'text',
'label' => $this->l('service_desc'),
'name' => 'service_desc',
'size' => 255,
'required' => true,
'desc' => $this->l('Enter name of Arrival port')
),
array(
'type' => 'text',
'label' => $this->l('charge'),
'name' => 'charge',
'size' => 255,
'required' => true,
'desc' => $this->l('Enter name of Arrival port')
),
array(
'type' => 'switch',
'label' => $this->l('Active'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Active')), array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Inactive')))),
),
'submit' => array('title' => $this->l('Save')),
'buttons' => array(
array(
'href' => Context::getContext()->link->getAdminLink('AdminGCardeliverycity', true) . '&updatecitydelivery&id_citydelivery=' . $id_citydelivery,
'title' => $this->l('Cancle'),
'icon' => 'process-icon-cancel'
)
)
)
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->toolbar_scroll = true;
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->identifier = $this->identifier;
$helper->submit_action = 'submit';
$helper->currentIndex = AdminController::$currentIndex;
$helper->token = Tools::getAdminTokenLite($this->name);
$id_additional_service = (int) Tools::getValue('id_additional_service');
$additionalServiceObj = new AdditionalServicesModel($id_additional_service);
$helper->tpl_vars = array(
'fields_value' => $this->getFormValues($additionalServiceObj),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
$_1 = $helper->generateForm(array($fields_form_1));
$return = $_1;
return $return;
}
function getFormValues($additionalServiceObj) {
return array(
'service_name' => Tools::getValue('service_name ', $additionalServiceObj->service_name),
'service_desc' => Tools::getValue('service_desc', $additionalServiceObj->service_desc),
'charge' => Tools::getValue('charge', $additionalServiceObj->charge),
'active' => Tools::getValue('active', $additionalServiceObj->active)
);
}
}
First of all, it seems that you redirect your page to the same URL. Try to use this
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
where
AdminHome
is a redirect URL, you need to replace it with yours.
And second, try to use
Tools::getIsset('yourButtonName')
instead of
Tools::isSubmit('yourButtonName')
and the last, if nothing mentioned above will not help, try to move
parent::initContent();
and put it after your condition
Probably redirect_after may be useful
$this->redirect_after = 'Your custom address';

AUTHENTICATE 2 LDAP USER IN ITOPS

I have some LDAP users in iTops, and i want to login with all of users in iTops. But i have an error like that "user not found in LDAP".
Which folders that i have to change ? So i can login with all LDAP users.
I appreciate for your responses, all of you. Please help me, thanks.
in config-itop.php
$MyModuleSettings = array(
'authent-ldap' => array (
'host' => '192.168.1.2',
'port' => 389,
'default_user' => 'anonim',
'default_pwd' => 'Admin123',
'base_dn' => 'dc=vokasiub,dc=COM',
'user_query' => '(samaccountname=%1$s)',
'options' => array (
17 => 3,
8 => 0,
),
'start_tls' => false,
'debug' => true,
),
'authent-ldap2' => array (
'host' => '192.168.2.2',
'port' => 389,
'default_user' => 'isoiso',
'default_pwd' => 'Admin123',
'base_dn' => 'ou=users ou, dc=bagusyekti,dc=COM',
'user_query' => '(samaccountname=%1$s)',
'options' => array (
17 => 3,
8 => 0,
),
'start_tls' => false,
'debug' => true,
),
'itop-attachments' => array (
'allowed_classes' => array (
0 => 'Ticket',
),
'position' => 'relations',
'preview_max_width' => 290,
),
'email-reply' => array (
'enabled_default' => true,
),
'itop-backup' => array (
'mysql_bindir' => '',
'week_days' => 'monday, tuesday, wednesday, thursday, friday',
'time' => '23:30',
'retention_count' => 5,
'enabled' => true,
'debug' => true,
),
);
iTop 2.7 and older
This was not possible.
iTop 3.0 and newer
This is now possible, check the full documentation here, but basically you have to set the different LDAP servers like this in the iTop configuration file:
'authent-ldap' => array (
'host' => 'localhost',
'port' => 389,
'default_user' => '',
'default_pwd' => '',
'base_dn' => 'dc=mycompany,dc=com',
'user_query' => '(&(uid=%1$s))',
'options' => array (
17 => 3,
8 => 0,
),
'debug' => false,
'servers' => array(
'MySecond-LDAP-Server' => array(
'host' => 'server1',
'port' => 389,
'default_user' => '',
'default_pwd' => '',
'base_dn' => 'dc=mycompany,dc=com',
'user_query' => '(&(uid=%1$s))',
'options' => array (
17 => 3,
8 => 0,
),
'debug' => false,
),
),
),

install.php is not being run during installation

My install.php is not being run during installation.I checked everywhere.To be sure,I ran the code in install.php elsewhere and it worked well. But during installation only the install.php is being skipped somehow.My module name is Hotelreservation, hence the code in install.php is as below. Why is there no error display during installation ?
<?php
class Hotelreservation_Installer extends Engine_Package_Installer_Module
{
public function onInstall()
{
$this->_hotelroomsBrowsePage();
parent::onInstall();
}
protected function _hotelroomsBrowsePage()
{
$db = $this->getDb();
// profile page
$page_id = $db->select()
->from('engine4_core_pages', 'page_id')
->where('name = ?', 'hotelreservation_index_browse')
->limit(1)
->query()
->fetchColumn();
if (!$page_id) {
// Insert page
$db->insert('engine4_core_pages', array(
'name' => 'hotelreservation_index_browse',
'displayname' => 'HotelRooms Browse Page',
'title' => 'Browse Rooms',
'description' => 'this page displays rooms',
'custom' => 0,
));
$page_id = $db->lastInsertId();
// Insert main
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'main',
'page_id' => $page_id,
));
$main_id = $db->lastInsertId();
// Insert middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 2,
));
$middle_id = $db->lastInsertId();
// Insert hotelreservation.browse-menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'hotelreservation.browse-menu',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 1,
));
// Insert core content
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'core.content',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 2,
));
// Insert left
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'left',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 3,
));
$left_id = $db->lastInsertId();
}
return $this;
}
}// end class
Did you add info to mainfest file like this in packages array
'callback' => array(
'path' => 'Your path to php file',
'class' => 'Hotelreservation_Installer',
),
I agree with Arif. Check the file manifest.php inside of //settings:
(info of module Album)
'callback' => array(
'path' => 'application/modules/Album/settings/install.php',
'class' => 'Album_Installer',
),
I had this same issue and got it to work.
It turns out that the installer looks in application/packages/module-yourmodule-x.x.x.json first. around line 35 you'll find:
"callback": {
"path": null,
"class": "Engine_Package_Installer_Module",
"priority": 100
},
change that to:
"callback": {
"path": "application/modules/Yourmodule/settings/install.php",
"class": "Yourmodule_Installer",
"priority": 100
},
now, when you run the installer, your install.php will be called.

Invalid type given. String expected - Zend Framework 2

Im working on Zend Framework 2 especially with Zend Forms. I have declared a Select dropdown box in
Form:
$selectElement = new Element\Select('selectElement');
$selectElement->setAttribute('title', 'Select a Value')
->setAttribute('id', 'id');
$data = array(
array(
//Fetching the values from database
),
);
$selectElement->setAttribute('multiple', 'multiple')
->setValueOptions($data);
$this->add($selectElement);
InputFilter:
$inputFilter->add($factory->createInput(array(
'name' => 'selectElement',
'required' => false,
'filters' => array(
array(
'name' => 'Int'
),
),
)));
I have used Zend Debug to get the values which are in the selectElement dropbox in this fashion:
$dataSelectElements = $this->getRequest()->getPost('selectElement');
\Zend\Debug\Debug::dump($dataSelectElements);
Debug Result:
array(4) {
[0] => string(2) "20"
[1] => string(2) "22"
[2] => string(2) "23"
[3] => string(2) "75"
}
Basically Im getting the id's from the selectElement form to store it in the database. Right now Im getting a notice and zend form error:
Notice Error:
Notice: Array to string conversion in ..\zendframework\zendframework\library\Zend\Filter\Int.php on line 29
And a form invalid error:
array(1) {
[0] => array(1) {
["selectElement "] => array(1) {
["explodeInvalid"] => string(35) "Invalid type given. String expected"
}
}
}
Is there a solution to over come this problem. Any help would be appreciated.
The Int filter will attempt to make an Integer out of your array of data, which is not going to work.
Previously I've used the Callback filter, which can be used to loop through the data and check if each value is an Int.
For example:
'filters' => array(
array(
'name' => 'Callback',
'options' => array(
'callback' => function($values) {
return array_filter($values, function($value) {
return ((int)$value == $value);
});
}
)
),
),
I did bit differently, something like this
form
class Companyform extends Form
{
public function __construct()
{
// we want to ignore the name passed
parent::__construct('company');
$this->setAttribute ('method', 'post');
$this->setAttribute ('class', 'form-horizontal');
$this->add ( array (
'name' => 'parentID',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'id' => 'parentID',
'type' => 'select',
'placeholder' => "Parent Company",
),
'options' => array(
'label' => 'Parent Company'
)
));
$this->add(array(
'name' => 'btnsubmit',
'attributes' => array(
'id' => 'btnsubmit',
'type' => 'submit',
'value' => 'Add',
'class' => 'btn btn-primary'
),
));
}
}
controller
public function addAction()
{
$request = $this->getRequest();
$companyList = $this->_getCompanyList();
$form = new Companyform();
$form->get('parentID')->setAttribute('options',$companyList);
if ($request->isPost())
{
$company = new Company();
$form->setInputFilter($company->getInputFilter());
$form->setData($request->getPost());
if ($form->isvalid())
{
}
}
}
public function _getCompanyList()
{
$companies = $this->Em()->getEntityManager()->getRepository('XXXX\Entity\Company')->findBy(array('isDeleted'=>'0'));
$companyIDList = array();
$companyIDList[0] = "No Parent";
foreach ($companies as $company)
{
$companyIDList[$company->id] = $company->companyName;
}
return $companyIDList;
}
Entity class
protected $inputFilter;
public function setInputFilter(InputFilterInterface $inputFilter)
{
throw new \Exception("Not used");
}
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'companyName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 2,
'max' => 255,
),
),
),
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
You may need to add following library in entity
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
In ZendFramework 2, when you creating a (add) element from your Form file, Check the attribute: inarrayvalidator is true.
$this->add(array(
'name' => 'select_name',
'type' => 'select',
'id' => 'select_name',
'options' => array(
'label' => 'Select Name',
),
'attributes' => array(
'id' => 'select_id',
'inarrayvalidator' => true,
),
));
I hope, this works...