Example module how to save data in the database - php

I cloned a module of prestashop 1.7 and everything works perfectly without any problem. What I would like to do (please) is save the data in the prestashop database itself but I can't do it I hope I have explained myself better
code
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class Stagenti extends Module
{
protected $config_form = false;
public function __construct()
{
$this->name = 'stagenti';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Lab';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Lab Agenti');
$this->description = $this->l('Gestionale per agenti di commercio');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL);
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
//$values[] = Tools::getValue('SOMETEXT_TEXT_'.$lang['id_lang']);
Configuration::updateValue('STAGENTI_TEXT_' . $lang['id_lang'], '', true);
Configuration::updateValue('STAGENTI_TEXT2_' . $lang['id_lang'], '', true);
}
include(dirname(__FILE__).'/sql/install.php');
return parent::install() &&
$this->registerHook('header') &&
$this->registerHook('backOfficeHeader') &&
$this->registerHook('displayBanner');
}
public function uninstall()
{
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
//$values[] = Tools::getValue('SOMETEXT_TEXT_'.$lang['id_lang']);
Configuration::deleteByName('STAGENTI_TEXT_' . $lang['id_lang']);
Configuration::deleteByName('STAGENTI_TEXT2_' . $lang['id_lang']);
}
include(dirname(__FILE__).'/sql/uninstall.php');
return parent::uninstall();
}
public function getContent()
{
if (((bool)Tools::isSubmit('submitStagentiModule')) == true) {
$this->postProcess();
}
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
return $output . $this->renderForm();
}
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitStagentiModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($this->getConfigForm()));
}
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Impostazioni'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'col' => 9,
'type' => 'text',
'desc' => $this->l('inserisci lo slogan che desideri far visualizzare'),
'name' => 'STAGENTI_TEXT2',
'label' => $this->l('Messaggio Slogan'),
'autoload_rte' => true,
'lang' => true
),
array(
'col' => 9,
'type' => 'textarea',
'desc' => $this->l('se inserisci una img le misure devono essere 1140 x 270 px'),
'name' => 'STAGENTI_TEXT',
'label' => $this->l('Messaggio riepilogo'),
'autoload_rte' => true,
'lang' => true
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
protected function getConfigFormValues()
{
$languages = Language::getLanguages(false);
$values = array();
foreach ($languages as $lang) {
$values['STAGENTI_TEXT'][$lang['id_lang']] = Configuration::get('STAGENTI_TEXT_' . $lang['id_lang']);
$values['STAGENTI_TEXT2'][$lang['id_lang']] = Configuration::get('STAGENTI_TEXT2_' . $lang['id_lang']);
}
return $values;
}
protected function postProcess()
{
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
Configuration::updateValue('STAGENTI_TEXT_' . $lang['id_lang'], Tools::getValue('STAGENTI_TEXT_' . $lang['id_lang']), true);
Configuration::updateValue('STAGENTI_TEXT2_' . $lang['id_lang'], Tools::getValue('STAGENTI_TEXT2_' . $lang['id_lang']), true);
}
}
public function hookBackOfficeHeader()
{
if (Tools::getValue('module_name') == $this->name) {
$this->context->controller->addJS($this->_path . 'views/js/back.js');
$this->context->controller->addCSS($this->_path . 'views/css/back.css');
}
}
public function hookHeader()
{
$this->context->controller->addJS($this->_path . 'views/js/front.js');
$this->context->controller->addCSS($this->_path . 'views/css/front.css');
}
public function hookDisplayBanner()
{
$some_string = Configuration::get('STAGENTI_TEXT_' . $this->context->language->id);
$this->context->smarty->assign([
'module_dir' => $this->_path,
'stagenti_message' => $some_string
]);
$some_string = Configuration::get('STAGENTI_TEXT2_' . $this->context->language->id);
$this->context->smarty->assign([
'module_dir' => $this->_path,
'stagenti_message5' => $some_string
]);
return $this->display(__FILE__, 'message.tpl');
}
}
database
<?php
$sql = array();
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . '` (
`id_stagenti` int(11) NOT NULL AUTO_INCREMENT,
`stagenti_text` text NOT NULL,
`stagenti_text2` text NOT NULL,
PRIMARY KEY (`id_infomess`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
foreach ($sql as $query) {
if (Db::getInstance()->execute($query) == false) {
return false;
}
}

Db::getInstance()->insert('your_table', array(
'stagenti_text' => pSQL($value1),
'stagenti_text2' => pSQL($value2),
));

Related

Cannot add any stylesheets to module in prestashop 1.7

I've encountered problem with adding any stylesheets to prestashop front office. I was reading multiple articles, tried multiple solutions and I can't get it to work. Adding styles to back office was not a problem (but that this code for adding styles to back office is workaround I think). Here is the module code. (I've added stylesheet import in multiple places to check every solution. In other modules this methods works as intended). Sorry for messy code I'm not that good in PHP.
<?php
if (!defined('_PS_VERSION_'))
exit();
class PromotionBanner extends Module
{
public function __construct()
{
$this->name = 'promotionbanner';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'example';
$this->author_uri = 'https://example.com';
$this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);
$this->bootstrap = true;
$this->need_instance = 0;
$this->dir = '/modules/promotionbanner';
$this->css_path = Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name
. '/' . $this->_path . 'views/css/';
parent::__construct();
$this->displayName = $this->l('Promotion Banner', 'promotionbanner');
$this->description = $this->l('This module provides configurable promotion banner on your website');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall the module?', 'promotionbanner');
}
private function updateConf()
{
Configuration::updateValue('banner_text', $this->l('Wybrane produkty tańsze o 15%! Kod rabatowy: '));
Configuration::updateValue('banner_coupon_code', $this->l('Wybierz kupon rabatowy'));
}
public function install()
{
$this->updateConf();
return parent::install() && $this -> registerHook('displayWrapperTop') && $this->registerHook('header');
}
public function uninstall()
{
if (!parent::uninstall() || !Configuration::deleteByName('promotionbanner_module') &&
!Configuration::deleteByName('banner_coupon_code'))
return false;
return true;
}
public function hookDisplayWrapperTop($params)
{
$this->context->smarty->assign(
array(
'banner_text' => Configuration::get('banner_text'),
'banner_coupon_code' => Configuration::get('banner_coupon_code')
)
);
$this->context->controller->registerStylesheet(
'modules-promotion-banner2', //This id has to be unique
'modules/'.$this->name.'/views/css/front.css',
array('media' => 'all', 'priority' => 150)
);
return $this->display(__FILE__, 'promotionbanner.tpl');
}
public function hookHeader() {
$this->context->controller->addCSS($this->_path . 'views/css/front.css', 'all');
$this->context->controller->registerStylesheet(
'modules-promotion-banner', //This id has to be unique
'modules/'.$this->name.'/views/css/front.css',
array('media' => 'all', 'priority' => 150)
);
}
public function hookActionFrontControllerSetMedia($params) {
$this->context->controller->registerStylesheet(
'module-promotionbanner-style',
'modules/'.$this->name.'/views/css/front.css',
[
'media' => 'all',
'priority' => 200,
]
);
}
public function getPromotions()
{
$cart_rule = _DB_PREFIX_ . 'cart_rule';
$request = "SELECT $cart_rule.id_cart_rule, " . _DB_PREFIX_ . "cart_rule_lang.name, $cart_rule.code " .
"FROM $cart_rule INNER JOIN " . _DB_PREFIX_ . 'cart_rule_lang ON ' . _DB_PREFIX_ . 'cart_rule.id_cart_rule='
. _DB_PREFIX_ . 'cart_rule_lang.id_cart_rule WHERE ' . _DB_PREFIX_ . 'cart_rule.code IS NOT NULL';
$db = Db::getInstance();
$cupons = $db->executeS($request);
$parsedCupons = array();
foreach ($cupons as $cupon) {
array_push($parsedCupons, array(
'code' => $cupon['code'],
'name' => $cupon['name']
));
}
return $parsedCupons;
}
public function displayForm()
{
$form = $this->renderForm();
$this->context->smarty->assign(array(
'banner_text' => Configuration::get('banner_text'),
'banner_coupon_code' => Configuration::get('banner_coupon_code'),
'form_url' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'),
'name' => $this->name,
'form_tpl' => $form,
'coupon_codes' => $this->getPromotions()
));
$this->context->controller->addCSS(array(
$this->css_path . 'fontawesome-all.min.css',
$this->css_path . 'module.css'
));
$this->output = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/menu.tpl');
return $this->output;
}
public function renderForm()
{
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
$helper->title = $this->displayName;
$helper->show_toolbar = false;
$helper->toolbar_scroll = false;
$helper->submit_action = 'submit' . $this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name .
'&token=' . Tools::getAdminTokenLite('AdminModules'),
)
);
$helper->fields_value = array(
'banner_text' => Configuration::get('banner_text'),
'banner_coupon_code' => Configuration::get('banner_coupon_code')
);
return $helper->generateForm(array($this->getConfigForm()));
}
public function getConfigForm()
{
$fields_form = array(
'form' => array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Banner text before code: '),
'name' => 'banner_text',
'lang' => false,
'required' => true,
'size' => 20
),
array(
'type' => 'select',
'label' => $this->l('Coupon code: '),
'name' => 'banner_coupon_code',
'required' => true,
'options' => array(
'query' => $this->getPromotions(),
'id' => 'code',
'name' => 'name'
)
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
)
);
return $fields_form;
}
public function getContent()
{
$output = "";
if (Tools::isSubmit('submit' . $this->name)) {
$banner_text = strval(Tools::getValue('banner_text'));
$banner_coupon_code = strval(Tools::getValue('banner_coupon_code'));
if (!isset($banner_text) || !isset($banner_coupon_code))
$output .= $this->displayError($this->l('Please insert something in this field.'));
else {
Configuration::updateValue('banner_text', $banner_text);
Configuration::updateValue('banner_coupon_code', $banner_coupon_code);
$output .= $this->displayConfirmation($this->l('Field updated successfully!'));
}
}
return $output . $this->displayForm();
}
}
Okay so I've managed to successfully register the stylesheet in the prestashop 1.7.6.1. But I think this is a good time to mention some of my mistakes and address some of the problems.
Checklist of registering a stylesheet in front office
Use correct hook for the job.
My problem has been unsolved because I've used a wrong hook.
Make sure that your __construct() registered a official hook for registering stylesheets (prestashop 1.7.x). The correct hook is: $this->registerHook('actionFrontControllerSetMedia'); you can find official docs here (If you don't have front controller in your module): https://devdocs.prestashop.com/1.7/themes/getting-started/asset-management/#without-a-front-controller-module
Make sure that you registered your hook function with $params (I don't know why but it doesn't work without a function parameter defined... This also stopped me from successfull register). The proper function should look like this:
$this->context->controller->registerStylesheet(
'stylesheet-id', //This id has to be unique
'modules/'.$this->name.'/views/css/front.css',
array('server' => 'local', 'priority' => 10)
);
}
As #bakis mentioned. After every try clear your browser cache + prestashop cache for chrome or chromium users I would suggest to disable the browser cache in inspector window completely.
I know that $this->context->controller->addCSS still exists, but this function is useful only for back office stylesheet register. Even the official docs are saying about it
Backward compatibility is kept for the addJS(), addCSS(), addJqueryUI() and addJqueryPlugin() methods.
That's pretty much everything about this question. I hope it will help someone in the future who is searching for answer.

Yii2 create data row works but update doesn't

I saw red some answers on similar questions but still can't understand where is my problem. I have a _form.php which is used when data row is created and updated аlso. When i create data row it is OK but when it redirects me to return $this->redirect(['view', 'id' => $model->id]); but the data is not updated. Tried to var_dump($model->getErrors()) (as I saw in the answers of another question) but it returns me and empty array.
These are my files:
Controller action:
public function actionUpdate($id)
{
$model = $this->findModel($id);
$settings = new Settings();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$languages = Lang::find()->all();
foreach ($languages as $language) {
if ($language->default != 1) {
$names = 'names_' . $language->url;
$varNames = Yii::$app->OutData->sanitize($model->$names);
$model->$names = $varNames;
$review = 'review_' . $language->url;
$varReview = Yii::$app->OutData->sanitize($model->$review);
$model->$review = $varReview;
$metaDesc = 'meta_desc_' . $language->url;
$varMetaDesc = Yii::$app->OutData->sanitize($model->$metaDesc);
$model->$metaDesc = $varMetaDesc;
$url = 'url_' . $language->url;
$varUrl = Yii::$app->OutData->sanitize($model->$url);
$model->$url = $varUrl;
$cBirth = 'country_birth_' . $language->url;
$varcBirth = Yii::$app->OutData->sanitize($model->$cBirth);
$model->$cBirth = $varcBirth;
}
else
{
$model->names = Yii::$app->OutData->sanitize($model->names);
$model->review = Yii::$app->OutData->sanitize($model->review);
$model->meta_desc = Yii::$app->OutData->sanitize($model->meta_desc);
$model->url= Yii::$app->OutData->sanitize($model->url);
$model->country_birth = Yii::$app->OutData->sanitize($model->country_birth);
}
}
//записване на изображенията + thumb
if (isset($_POST["Author"]["imageFiles"]) and ! empty($_POST["Author"]["imageFiles"])) {
$model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
if (isset($model->imageFiles) and count($model->imageFiles) > 0) {
foreach ($model->imageFiles as $key => $file) {
$parseProdTitle = MakeURL::parseImageName($model->names.'_'.$model->id);
$fileName = $parseProdTitle . '_' . $model->id . '.' . $file->extension;
$fileName = Yii::$app->translate->cyr_to_lat($fileName);
$model->filename = $fileName;
$model->save(false);
$pic = Yii::getAlias('#frontend/web') . '/authors/thumb-270/' . $fileName;
$pic2 = Yii::getAlias('#frontend/web') . '/authors/' . $fileName;
$file->saveAs(Yii::getAlias('#frontend/web') . '/authors/' . $fileName);
$image = file_get_contents(Yii::getAlias('#frontend/web') . '/authors/' . $fileName);
file_put_contents($pic, $image);
$model->resizeImg($pic);
$settings->compress($pic, $pic, 90);
$settings->compress($pic2, $pic2, 90);
}
}
}
if($model->update()){
var_dump(1);die;
}else{
var_dump($model->getErrors());die;// it dumps here but it returns an empty array
}
if($model->validate()){
var_dump(1);die;// it dumps here so validate is ok ( I guess )
}else{
var_dump($model->getErrors());die;
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
And my model:
<?php
namespace backend\models;
use Yii;
use omgdef\multilingual\MultilingualBehavior;
use omgdef\multilingual\MultilingualQuery;
use kartik\helpers\Html;
/**
* This is the model class for table "author".
*
* #property integer $id
* #property integer $active
* #property string $filename
* #property integer $sort
* #property data $birthday
*
* #property AuthorLang[] $authorLangs
*/
class Author extends \yii\db\ActiveRecord
{
public $imageFiles;
private $languages = array();
public function __construct() {
foreach(Yii::$app->params['languages'] as $langArr){
$langParam = new Lang;
$langParam->id = $langArr['id'];
$langParam->url = $langArr['url'];
$langParam->local = $langArr['local'];
$langParam->name = $langArr['name'];
$langParam->default = $langArr['default'];
$langParam->active = $langArr['active'];
$this->languages[] = $langParam;
}
parent::__construct();
}
public static function find()
{
return new MultilingualQuery(get_called_class());
}
public function behaviors()
{
$languagesArray = [];
foreach($this->languages as $language){
if($language->default){
$defLang = $language->url;
}
$languagesArray[$language->local] = $language->name;
}
return [
'ml' => [
'class' => MultilingualBehavior::className(),
'languages' => $languagesArray,
//'languageField' => 'language',
//'localizedPrefix' => '',
//'requireTranslations' => false',
//'dynamicLangClass' => true',
//'langClassName' => PostLang::className(), // or namespace/for/a/class/PostLang
'defaultLanguage' => $defLang,
'langForeignKey' => 'author_id',
'tableName' => "{{%authorLang}}",
'attributes' => [
'names',
'review',
'meta_desc',
'url',
'country_birth',
]
],
];
}
/**
* #inheritdoc
*/
public static function tableName()
{
return 'author';
}
/**
* #inheritdoc
*/
public function rules()
{
$required = ['names', 'review', 'meta_desc', 'url', 'birthday', 'country_birth'];
$this->checkLanguage([$required]);
return [
[['active', 'sort'], 'required'],
[$required, 'required'],
['names', 'string', 'max' => 255],
['country_birth', 'string', 'max' => 255],
['review', 'string'],
['meta_desc', 'string', 'max' => 170],
['url', 'string', 'max' => 60],
[['active', 'sort'], 'integer'],
[['filename'], 'string'],
];
}
protected function checkLanguage($megaArr = [])
{
foreach ($this->languages as $language)
{
if($language->default != 1)
{
foreach ($megaArr as $fields)
{
foreach ($fields as $field)
{
$field .= '_' . $language->url;
}
}
}
}
}
public function changeActiveForm() {
$active = "";
if ($this->active == 1) {
$active = 'checked="checked"';
}
return '<label class="switch switch-custom block mbn taCenter">
<input type="checkbox" value="1" id="check_' . $this->id . '" name="field_types" class="legend-switch" ' . $active . ' onchange="changeStatusActive(' . $this->id . ', \'author\');"></input>
<label data-off="' . Yii::t('app', 'Не') . '" data-on="' . Yii::t('app', 'Да') . '" for="check_' . $this->id . '"></label>
<span></span>
</label>';
}
public function getKartikImagesList() {
$doctorImagesArr = array();
$doctorImages = Author::find()->where('id = :id', [':id' => $this->id])->orderBy(['id' => SORT_ASC])->one();
if(isset($doctorImages->filename) and $doctorImages->filename!="" and $doctorImages->filename!=Null) {
$fileName = Yii::getAlias('#frontend/web') . "/authors/" . $doctorImages->filename;
if (file_exists($fileName)) {
$fileNameUrl = Yii::$app->urlManagerFrontend->baseUrl . "/authors/thumb-270/" . $doctorImages->filename;
$doctorImagesArr[] = Html::img($fileNameUrl, ['class' => 'file-preview-image', 'style' => 'width: 350px;']) .
'<span class="glyphicons glyphicons-bin"></span>';
}
}
return $doctorImagesArr;
}
public function resizeImg($img) {
$sz = getimagesize($img);
$ratio = $sz[0] / $sz[1]; // w/h
$w2 = Yii::$app->params['thumbswidth']; // thumb 1 width
$image = new SimpleImage();
$image->load($img);
$image->resize($w2, round($w2 / $ratio));
$image->save($img);
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'active' => Yii::t('app','app.Active' ),
'filename' => Yii::t('app','app.Filename' ),
'sort' => Yii::t('app','app.Sort' ),
'country_birth' => Yii::t('app','app.Birth Country' ),
'names' => Yii::t('app','app.Names' ),
'meta_desc' => Yii::t('app','app.Meta Desc' ),
'filename' => Yii::t('app','app.Image' ),
'birthday' => Yii::t('app','app.Birthday' ),
'imageFiles' => Yii::t('app','app.Image' ),
'description' => Yii::t('app','app.Review' ),
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getAuthorLangs()
{
return $this->hasMany(AuthorLang::className(), ['author_id' => 'id']);
}
}
I didn't post the _form.php because it is the same for both actions (create and update) and I think that the problem is not in it.If you need it will update my question immediately. Thank you in advance!
For some reason it is possible that the update does not affect any row in the table. In this case the function return 0 .. for check this situation you should chek this this way
http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#update()-detail
if($model->update() !== false){
var_dump(1);die;
}else{
var_dump($model->getErrors());die;// it dumps here but it returns an empty array
}
then, just for debugging, you could also try using $model->save(false) instead of $model->update() ... this way the $model is saved without regarding the validation rules ..

PrestaShop, Class not found in ModuleAdminController::getController

i'm trying to develop a PrestaShop module with controllers i placed, for example in:
/modules/mymodule/controllers/admin/myControlController.php
class MyControlController extends ModuleAdminController {
public function __construct() {
$this->module = 'mymodule';
$this->bootstrap = true;
$this->context = Context::getContext();
$token = Tools::getAdminTokenLite('AdminModules');
$currentIndex='index.php?controller=AdminModules&token='.$token.'&configure=mymodule&tab_module=administration&module_name=mymodule';
Tools::redirectAdmin($currentIndex);
parent::__construct();
}
public function showForm() {
die("hello");
}}
Controller works (construct method is called) if i call it form url
http://myshop.com/adminxxx/index.php?controller=MyControl&token=9faf638aa961468c8563ffb030b3c4a8
But i can't access methods of controller from main class of module:
ModuleAdminController::getController('MyControl')->showForm();
I received "Class not found" ever
Is that the correct method to access a control from outside?
Thanks!
If you want to show anything that concern a form you should use renderForm().
Your should try parent::showForm(); or $this->showForm();.
Here is an example of controller that can work :
require_once _PS_MODULE_DIR_.'modulename/models/ModuleNameLog.php';
require_once _PS_MODULE_DIR_.'modulename/modulename.php';
class AdminModuleNameLogController extends ModuleAdminController
{
protected $_defaultOrderBy = 'id_modulenamelog';
protected $_defaultOrderWay = 'DESC';
public function __construct()
{
$this->table = 'modulenamelog';
$this->className = 'ModuleNameLog';
$this->context = Context::getContext();
$this->lang = false;
$this->bootstrap = true;
$this->actions_available = array();
$this->actions = array();
$this->show_toolbar = false;
$this->toolbar_btn['new'] = array();
$this->tabAccess['add'] = '0';
$this->allow_export = true;
$this->requiredDatabase = true;
$this->page_header_toolbar_title = $this->l('Example Module Name logs');
$this->_select = 'SUM(a.quantity) as total_quantity';
$this->_group = ' GROUP BY a.id_product, a.id_product_attribute ';
$this->fields_list = array(
'id_product' => array(
'title' => $this->l('Product'),
'align' => 'center',
'callback' => 'getProductName',
),
'id_product_attribute' => array(
'title' => $this->l('Combination'),
'align' => 'center',
'callback' => 'getAttributeName',
),
'total_quantity' => array(
'title' => $this->l('Total Quantity'),
'align' => 'center',
),
);
$this->mod = new ModuleName();
$this->mod->cleanLogs();
$this->context = Context::getContext();
parent::__construct();
}
public function getProductName($id)
{
if (!empty($id)) {
$product = new Product($id, true, $this->context->cookie->id_lang);
return $product->name;
}
}
public function getAttributeName($id)
{
if (!empty($id)) {
$combination = new Combination($id);
$names = $combination->getAttributesName($this->context->cookie->id_lang);
$str = array();
if (!empty($names)) {
foreach ($names as $value) {
$str[] = $value['name'];
}
}
return implode(' - ', $str);
} else {
return '-';
}
}
public function postProcess()
{
if (Tools::isSubmit('purge_id')) {
// Do something here
$id = (int) Tools::getValue('purge_id');
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModuleNameLog').'&conf=4');
}
parent::postProcess();
}
public function renderList()
{
$carts = Db::getInstance()->executeS('SELECT ct.*, cs.`firstname`, cs.`lastname` FROM '._DB_PREFIX_.'cart ct LEFT JOIN '._DB_PREFIX_.'customer cs ON ct.id_customer = cs.id_customer WHERE 1 ORDER BY id_cart DESC LIMIT 0,2000');
$tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'modulename/views/templates/admin/preform.tpl');
$tpl->assign(array(
'carts' => $carts,
));
$html = $tpl->fetch();
return $html.parent::renderList();
}
public function renderForm()
{
if (!$this->loadObject(true)) {
return;
}
$obj = $this->loadObject(true);
if (isset($obj->id)) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
$array_submit = array(
array(
'type' => 'select',
'label' => $this->l('Cart :'),
'name' => 'id_cart',
'options' => array(
'query' => Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'cart WHERE id_cart > 0 ORDER BY id_cart DESC LIMIT 0,500'),
'id' => 'id_cart',
'name' => 'id_cart',
),
),
array(
'type' => 'text',
'label' => $this->l('Quantity translation here'),
'hint' => $this->l('Description and translation here'),
'name' => 'quantity',
),
);
$this->fields_form[0]['form'] = array(
'tinymce' => false,
'legend' => array(
'title' => $this->l('Form title'),
),
'input' => $array_submit,
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default',
),
);
$this->multiple_fieldsets = true;
return parent::renderForm();
}
}

After installing prestashop custom module geting error Fatal error: Call to undefined method when clicking the menu

After installing prestashop custom module getting Fatal error: Call to undefined method when clicking the menu which is created by the module
Fatal error: Call to undefined method querydr::viewAccess() in D:\xampp\htdocs\raffleV1.3\oknr9hexztcseff5\functions.php on line 279
<?php
if (!defined('_PS_VERSION_')) exit;
class querydr extends Module
{
protected $config_form = false;
public $html;
public $tabName = 'renderForm';
public function __construct()
{
$this->name = 'querydr';
$this->tab = 'others';
$this->version = '1.0.0';
$this->author = 'xyz';
$this->need_instance = 1;
$this->module_key = 'f35950b303e7cbcda7fd8e56bb100d77121';
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Query DR');
$this->description = $this->l('Allow your Back Office to Query the transactions ');
$this->confirmUninstall = $this->l('You want to Uninstall Query DR ?.');
$this->_tabsArray = array(
'Querydr' => 'Query DR',
);
if (!Configuration::get('QUERYDR'))
$this->warning = $this->l('No name provided');
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
include(dirname(__FILE__).'/sql/install.php');
return parent::install() &&
Configuration::updateValue('QUERYDR','Query Dr')
&& $this->_installTabs();
}
private function _installTabs()
{
$parentTab = new Tab();
foreach (Language::getLanguages() as $language) $parentTab->name[$language['id_lang']] = 'Query Dr';
$parentTab->class_name = 'Querydr';
$parentTab->module = $this->name;
$parentTab->id_parent = 0;
if (!$parentTab->save()) return false;
else {
$idTab = $parentTab->id;
//$idEn = Language::getIdByIso('en');
foreach ($this->_tabsArray as $tabKey => $name) {
$childTab = new Tab();
foreach (Language::getLanguages() as $language) $childTab->name[$language['id_lang']] = $name;
$childTab->class_name = $tabKey;
$childTab->module = $this->name;
$childTab->id_parent = $idTab;
if (!$childTab->save()) return false;
}
}
return true;
}
public function uninstall()
{
include(dirname(__FILE__).'/sql/uninstall.php');
Configuration::deleteByName('QUERYDR');
Configuration::deleteByName('QUERYDR_MERCHANT_ID');
Configuration::deleteByName('QUERYDR_SECRET_KEY');
$this->_uninstallTabs();
if (!parent::uninstall())
return false;
return true;
}
private function _uninstallTabs()
{
foreach ($this->_tabsArray as $tabKey => $name) {
$idTab = Tab::getIdFromClassName($tabKey);
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
}
}
$idTab = Tab::getIdFromClassName('QueryDr');
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
}
return true;
}
public function getContent()
{
if (Tools::isSubmit('submitQueryDrModule')) {
Configuration::updateValue('QUERYDR_MERCHANT_ID', Tools::getValue('QUERYDR_MERCHANT_ID'));
Configuration::updateValue('QUERYDR_SECRET_KEY', Tools::getValue('QUERYDR_SECRET_KEY'));
$this->html .= $this->displayConfirmation($this->l('Settings Updated'));
$this->tabName = 'renderForm';
}
if ($this->tabName) {
$this->html .= '<script>$(document).ready(function(){$("#'.$this->tabName.'").addClass("active");$(".'.$this->tabName.'").parents(".nav-tabs > li").addClass("active");});</script>';
} else {
$this->html .= '<script>$(document).ready(function(){$("#renderForm").addClass("active"); $(this).attr("href").indexOf("#renderForm").addClass("active");});</script>';
}
$this->html .= '<ul class="nav nav-tabs" role="tablist"><li ><a class="renderForm" href="#renderForm" role="tab" data-toggle="tab">SETTINGS</a></li></ul>';
$this->html .= '<div class="tab-content"><div class="tab-pane " id="renderForm">'.$this->renderForm_1_6().'</div></div>';
$this->html .='<style>div.flash.fail {color: #cd0a0a;background-color: #fef1ec;border: #cd0a0a 1px solid; padding: 0.5em;margin: 0 3px;margin-top: 22px;margin-bottom: 12px;text-align: center;border-radius: 2px 2px 2px 2px;}</style>';
return $this->html;
}
protected function renderForm_1_6()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'col' => 3,
'type' => 'text',
'desc' => $this->l('Your merchant ID ex: 201408191000001'),
'name' => 'QUERYDR_MERCHANT_ID',
'label' => $this->l('MERCHANT ID'),
), array(
'col' => 3,
'type' => 'text',
'desc' => $this->l('Your key provided by network international'),
'name' => 'QUERYDR_SECRET_KEY',
'label' => $this->l('SECRET KEY'),
)
),
'submit' => array(
'title' => $this->l('Save'),
),
)
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitQueryDrModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array(
$fields_form));
}
protected function getConfigFormValues()
{
return array(
'QUERYDR_MERCHANT_ID' => Configuration::get('QUERYDR_MERCHANT_ID'),
'QUERYDR_SECRET_KEY' => Configuration::get('QUERYDR_SECRET_KEY'),
);
}
}
My module link is here --
https://www.dropbox.com/s/juyhcu5zub8p9fi/querydr.zip?dl=0
I am not sure if it gonna help you but ... try to prefix your admin controller name with "Admin" like "AdminQuerydrController"and change it also in your tab installation
tab->class_name = 'AdminQuerydrController';
make sure to change also your controller php file name
"AdminQuerydrController.php"

syntax error, unexpected 'foreach' (T_FOREACH)

I've got a syntax error on my foreach. I want to select from my backoffice a text file which write all eamil from site. I want to only get email from my database and put them into a text file write in my hard disk.
<?php
if (!defined('_PS_VERSION_'))
exit;
class SuperModule extends Module
{
public function __construct()
{
$this->name = 'supermodule';
$this->tab = 'administration';
$this->version = 1.0;
$this->author = 'Lelu Matthias';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My super module');
$this->description = $this->l('This module is super !');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided.');
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
return parent::install() &&
$this->registerHook('displayNav') &&
$this->registerHook('header') &&
Configuration::updateValue('MYMODULE_NAME', 'super module') &&
Configuration::updateValue('MOD_SUPERMODULE_OPENINGHOURS', 'Ouvert de 9h a 19h') && Configuration::updateValue('MOD_SUPERMODULE_NEWSLETTER', '0');
}
public function uninstall()
{
return parent::uninstall();
}
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit_openinghours'))
{
$supermodule_openinghours = Tools::getValue('MOD_SUPERMODULE_OPENINGHOURS');
if (!$supermodule_openinghours || empty($supermodule_openinghours) || !
Validate::isGenericName($supermodule_openinghours))
$output .= $this->displayError( $this->l('Invalid Configuration value') );
else
{
Configuration::updateValue('MOD_SUPERMODULE_OPENINGHOURS',
$supermodule_openinghours);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
if (Tools::isSubmit('submit_exportnewsletter'))
{
$id_option = Tools::getValue('MOD_SUPERMODULE_NEWSLETTER');
$output .=$id_option;
$txt="";
if($id_option ==1)
{
(foreach $newsletter as $row)
{
$text.=$row['email'];}
$table='newsletter';
}
else
{
(foreach $customer as $row)
{
$text.=$row['email'];
}
$table='customer';
}
$date = gmdate('dmY');
$file = fopen(dirname(__FILE__).'/export-newsletter-'.$table.'-'.
$date.'.txt', 'w');
fputs($file, $txt);
fclose($file);
}
return $output.$this->displayForm1().$this->displayForm2();
}
public function displayForm1()
{
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$fields_form[0]['form'] = $this->formulaire1();
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->
name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::
$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MOD_SUPERMODULE_OPENINGHOURS'] =
Configuration::get('MOD_SUPERMODULE_OPENINGHOURS');
return $helper->generateForm($fields_form);
}
protected function formulaire1()
{
return array(
'legend' => array(
'title' => $this->l('Opening hours'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Opening hours'),
'name' => 'MOD_SUPERMODULE_OPENINGHOURS',
'size' => 20,
'required' => true
),
),
'submit' => array(
'name' => 'submit_openinghours',
'title' => $this->l('Save')
)
);
}
protected function formulaire2()
{
$options = array(
array(
'id_option' => 0,
'name' => $this->l('Customer table')
),
array(
'id_option' => 1,
'name' => $this->l('Newsletter table')
),
);
return array(
'legend' => array(
'title' => $this->l('Newsletter export'),
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Choice a table'),
'name' => 'MOD_SUPERMODULE_NEWSLETTER',
'desc' => $this->l('Please choice a table.'),
'options' => array(
'query' => $options,
'id' => 'id_option',
'name' => 'name'
),
),
),
'submit' => array(
'name' => 'submit_exportnewsletter',
'title' => $this->l('Save')
)
);
}
public function displayForm2()
{
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$fields_form[0]['form'] = $this->formulaire2();
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href'=>AdminController::$currentIndex.'&configure='.$this->name.
'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::
$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MOD_SUPERMODULE_NEWSLETTER'] =
Configuration::get('MOD_SUPERMODULE_NEWSLETTER');
return $helper->generateForm($fields_form);
}
public function hookDisplayNav($params)
{
$ma_variable = Configuration::get('MOD_SUPERMODULE_OPENINGHOURS');
$this->context->smarty->assign(array(
'ma_variable' => $ma_variable
));
return $this->display(__FILE__, 'supermodulenav.tpl');
}
public function hookDisplayHeader()
{
$this->context->controller->addCSS($this->_path.'css/supermodule.css', 'all');
}
public function GetMailNewsLetter()
{
$sql='SELECT email FROM '._DB_PREFIX_.'newsletter';
$newsletter=Db::getInstance()->executeS($sql);
return $newsletter;
}
public function GetMailCustomer()
{
$sql='SELECT email FROM '._DB_PREFIX_.'customer';
$customer=Db::getInstance()->executeS($sql);
return $customer;
}
}
Try this
foreach ($newsletter as $row)
Check the Manual here
Hey only change your (foreach $newsletter as $row) to foreach($newsletter as $row)
something like this
<?php
if (!defined('_PS_VERSION_'))
exit;
class SuperModule extends Module
{
public function __construct()
{
$this->name = 'supermodule';
$this->tab = 'administration';
$this->version = 1.0;
$this->author = 'Lelu Matthias';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My super module');
$this->description = $this->l('This module is super !');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided.');
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
return parent::install() &&
$this->registerHook('displayNav') &&
$this->registerHook('header') &&
Configuration::updateValue('MYMODULE_NAME', 'super module') &&
Configuration::updateValue('MOD_SUPERMODULE_OPENINGHOURS', 'Ouvert de 9h a 19h') && Configuration::updateValue('MOD_SUPERMODULE_NEWSLETTER', '0');
}
public function uninstall()
{
return parent::uninstall();
}
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit_openinghours'))
{
$supermodule_openinghours = Tools::getValue('MOD_SUPERMODULE_OPENINGHOURS');
if (!$supermodule_openinghours || empty($supermodule_openinghours) || !
Validate::isGenericName($supermodule_openinghours))
$output .= $this->displayError( $this->l('Invalid Configuration value') );
else
{
Configuration::updateValue('MOD_SUPERMODULE_OPENINGHOURS',
$supermodule_openinghours);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
if (Tools::isSubmit('submit_exportnewsletter'))
{
$id_option = Tools::getValue('MOD_SUPERMODULE_NEWSLETTER');
$output .=$id_option;
$txt="";
if($id_option ==1)
{
foreach ($newsletter as $row)
{
$text.=$row['email'];
}
$table='newsletter';
}
else
{
foreach ($customer as $row)
{
$text.=$row['email'];
}
$table='customer';
}
$date = gmdate('dmY');
$file = fopen(dirname(__FILE__).'/export-newsletter-'.$table.'-'.
$date.'.txt', 'w');
fputs($file, $txt);
fclose($file);
}
return $output.$this->displayForm1().$this->displayForm2();
}
public function displayForm1()
{
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$fields_form[0]['form'] = $this->formulaire1();
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->
name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::
$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MOD_SUPERMODULE_OPENINGHOURS'] =
Configuration::get('MOD_SUPERMODULE_OPENINGHOURS');
return $helper->generateForm($fields_form);
}
protected function formulaire1()
{
return array(
'legend' => array(
'title' => $this->l('Opening hours'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Opening hours'),
'name' => 'MOD_SUPERMODULE_OPENINGHOURS',
'size' => 20,
'required' => true
),
),
'submit' => array(
'name' => 'submit_openinghours',
'title' => $this->l('Save')
)
);
}
protected function formulaire2()
{
$options = array(
array(
'id_option' => 0,
'name' => $this->l('Customer table')
),
array(
'id_option' => 1,
'name' => $this->l('Newsletter table')
),
);
return array(
'legend' => array(
'title' => $this->l('Newsletter export'),
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Choice a table'),
'name' => 'MOD_SUPERMODULE_NEWSLETTER',
'desc' => $this->l('Please choice a table.'),
'options' => array(
'query' => $options,
'id' => 'id_option',
'name' => 'name'
),
),
),
'submit' => array(
'name' => 'submit_exportnewsletter',
'title' => $this->l('Save')
)
);
}
public function displayForm2()
{
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$fields_form[0]['form'] = $this->formulaire2();
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href'=>AdminController::$currentIndex.'&configure='.$this->name.
'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::
$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['MOD_SUPERMODULE_NEWSLETTER'] =
Configuration::get('MOD_SUPERMODULE_NEWSLETTER');
return $helper->generateForm($fields_form);
}
public function hookDisplayNav($params)
{
$ma_variable = Configuration::get('MOD_SUPERMODULE_OPENINGHOURS');
$this->context->smarty->assign(array(
'ma_variable' => $ma_variable
));
return $this->display(__FILE__, 'supermodulenav.tpl');
}
public function hookDisplayHeader()
{
$this->context->controller->addCSS($this->_path.'css/supermodule.css', 'all');
}
public function GetMailNewsLetter()
{
$sql='SELECT email FROM '._DB_PREFIX_.'newsletter';
$newsletter=Db::getInstance()->executeS($sql);
return $newsletter;
}
public function GetMailCustomer()
{
$sql='SELECT email FROM '._DB_PREFIX_.'customer';
$customer=Db::getInstance()->executeS($sql);
return $customer;
}
}
I think it help you
You are using wrong foreach syntax.follow the given below code.also check this and this
(foreach $newsletter as $row) // it is not a correct syntax
foreach ($newsletter as $row) // this is a correct syntax
(foreach $customer as $row) // it is not a correct syntax
foreach ($customer as $row) // this is a correct syntax
wrong syntax:
(foreach $newsletter as $row)
Correct Syntax
foreach($newsletter as $row)
The correct syntax of foreach is
foreach($newsletter as $row)
{
}
Not
(foreach $newsletter as $row)

Categories