Prestashop override admin template - php

I have the code (for prestashop 1.5):
class AdminTestController extends AdminController
{
public $identifier = 'id_test';
function __construct() {
parent::__construct();
$this->table = 'test';
$this->className = 'test';
/*$this->fields_list = array(
'id_test' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'content' => array('title' => $this->l('Test'), 'width' => 'auto')
);*/
$this->fields_options = array(
'general' => array(
'title' => $this->l(''),
'icon' => 'tab-preferences',
'fields' => array(
'TEST' => array(
'type' => 'textarea',
'label' => $this->l('TEST'),
'title' => $this->l('TEST'),
'name' => 'test',
'autoload_rte' => true,
'lang' => true,
'rows' => 15,
'cols' => 70,
//'hint' => $this->l('Invalid characters:').' <>;=#{}'
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
)
);
}
}
I want to attach tinyMCE to my textarea. I need to override one template but I can't find which one.
I tried:
template/controllers/test/list/list.tpl
template/controllers/test/form.form.tpl
How can I override the template for my controller?

Just for information. I override option/option.tpl; Now it works.

Related

Split Mailalerts module recipients in prestashop

I need a specific list of recipients to receive stocks alerts only and another list of recipients to receive only the new order alert.
What is the best way to do it?
Thank you
Here is how I would deal with this question:
Create the override file /override/modules/mailalerts/mailalerts.php with this code:
<?php
class MailAlertsOverride extends MailAlerts
{
protected $merchant_mails_stock;
protected function init()
{
parent::init();
$this->merchant_mails_stock = str_replace(',', self::__MA_MAIL_DELIMITOR__, (string)Configuration::get('MA_MERCHANT_MAILS_STOCK'));
}
public function install($delete_params = true)
{
if (! parent::install($delete_params))
return false;
if ($delete_params)
{
Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('PS_SHOP_EMAIL'));
}
return true;
}
public function uninstall($delete_params = true)
{
if ($delete_params)
{
Configuration::deleteByName('MA_MERCHANT_MAILS_STOCK');
}
return parent::uninstall();
}
protected function postProcess()
{
$errors = array();
if (Tools::isSubmit('submitMAMerchant'))
{
$emails = (string)Tools::getValue('MA_MERCHANT_MAILS_STOCK');
if (!$emails || empty($emails))
$errors[] = $this->l('Please type one (or more) e-mail address');
else
{
$emails = str_replace(',', self::__MA_MAIL_DELIMITOR__, $emails);
$emails = explode(self::__MA_MAIL_DELIMITOR__, $emails);
foreach ($emails as $k => $email)
{
$email = trim($email);
if (!empty($email) && !Validate::isEmail($email))
{
$errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email);
break;
}
elseif (!empty($email) && count($email) > 0)
$emails[$k] = $email;
else
unset($emails[$k]);
}
$emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
if (!Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', (string)$emails))
$errors[] = $this->l('Cannot update settings');
}
}
if (count($errors) > 0)
{
$this->html .= $this->displayError(implode('<br />', $errors));
return $this->init();
}
parent::postProcess();
}
public function hookActionUpdateQuantity($params)
{
$this->merchant_mails = $this->merchant_mails_stock;
parent::hookActionUpdateQuantity($params);
}
public function renderForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Customer notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Product availability'),
'name' => 'MA_CUSTOMER_QTY',
'desc' => $this->l('Gives the customer the option of receiving a notification when an out-of-stock product is available again.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Order edit'),
'name' => 'MA_ORDER_EDIT',
'desc' => $this->l('Send a notification to the customer when an order is edited.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMailAlert',
)
),
);
$fields_form_2 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Merchant notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('New order'),
'name' => 'MA_MERCHANT_ORDER',
'desc' => $this->l('Receive a notification when an order is placed.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Out of stock'),
'name' => 'MA_MERCHANT_OOS',
'desc' => $this->l('Receive a notification if the available quantity of a product is below the following threshold.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Threshold'),
'name' => 'MA_LAST_QTIES',
'class' => 'fixed-width-xs',
'desc' => $this->l('Quantity for which a product is considered out of stock.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Coverage warning'),
'name' => 'MA_MERCHANT_COVERAGE',
'desc' => $this->l('Receive a notification when a product has insufficient coverage.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Coverage'),
'name' => 'MA_PRODUCT_COVERAGE',
'class' => 'fixed-width-xs',
'desc' => $this->l('Stock coverage, in days. Also, the stock coverage of a given product will be calculated based on this number.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Returns'),
'name' => 'MA_RETURN_SLIP',
'desc' => $this->l('Receive a notification when a customer requests a merchandise return.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail addresses'),
'name' => 'MA_MERCHANT_MAILS',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail stock addresses'),
'name' => 'MA_MERCHANT_MAILS_STOCK',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMAMerchant',
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitMailAlertConfiguration';
$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->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1, $fields_form_2));
}
public function getConfigFieldsValues()
{
$config = parent::getConfigFieldsValues();
$config['MA_MERCHANT_MAILS_STOCK'] = Tools::getValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('MA_MERCHANT_MAILS_STOCK'));
return $config;
}
}

PrestaShop: create admin tab and show records with edit/update/delete action

I have been trying to implement Admin Tab in PrestaShop. I want to show records from database. For each records I want to have Edit, update, Delete options.
My controllers/admin/AdminEblpayment.php file contains following code:
class AdminEblpaymentController extends ModuleAdminController
{
public function __construct()
{
$this->className = 'EblPaymentModel';
$this->table = 'ebl_payments';
$this->identifier = "id";
$this->_defaultOrderBy = 'created_at';
$this->_defaultOrderWay = 'desc';
$this->orderBy = "created_at";
$this->orderWay = "desc";
$this->meta_title = $this->l('EBL payment attempts');
$this->deleted = false;
//$this->explicitSelect = true;
$this->list_no_link = true;
$this->context = Context::getContext();
//$this->lang = true;
$this->bootstrap = true;
$this->sortedTree = array();
if (Shop::isFeatureActive()) {
Shop::addTableAssociation($this->table, array('type' => 'shop'));
}
$this->addRowAction('edit');
$this->addRowAction('details');
$this->addRowAction('updatestatus');
$this->addRowAction('cart');
$this->fields_list = array(
'id' => array(
'title' => $this->l('ID'),
'type' => 'int',
'align' => 'center',
'width' => 25,
),
'cart_id' => array(
'title' => $this->l('Cart id'),
'width' => 'auto',
'orderby' => false
),
'order_id' => array(
'title' => $this->l('Order id'),
'width' => 'auto',
'orderby' => false
),
'status' => array(
'title' => $this->l('Status'),
'width' => 'auto',
'orderby' => false
),
'result' => array(
'title' => $this->l('Result'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'result_code' => array(
'title' => $this->l('Result code'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'dbbl_transaction_id' => array(
'title' => $this->l('Transaction id'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'dbbl_response' => array(
'title' => $this->l('Response'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'created_at' => array(
'title' => $this->l('Created at'),
'width' => 70,
'align' => 'center',
'orderby' => true
),
'updated_at' => array(
'title' => $this->l('Updated at'),
'width' => 70,
'align' => 'center',
'orderby' => true
)
);
parent::__construct();
}
}
My models/EblpaymentModel.php file contains following code:
class EblPaymentModel extends ObjectModel
{
private $_catTree = array();
public $id;
public $cart_id;
public $order_id;
public $ebl_order_id;
public $ebl_status;
public $ebl_result;
public $ebl_result_code;
public $ebl_card_number;
public $ebl_transaction_id;
public $ebl_request;
public $ebl_response;
public $created_at;
public $updated_at;
//Multilang Fields
public $name;
public $description;
public $meta_description;
public $link_rewrite;
/**
* #see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'ebl_payments',
'primary' => 'id',
'multilang' => false,
'fields' => array(
//Fields
'cart_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'order_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_order_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_status' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_result' => array('type' => self::TYPE_INT),
'ebl_result_code' => array('type' => self::TYPE_STRING),
'ebl_card_number' => array('type' => self::TYPE_STRING),
'ebl_transaction_id' => array('type' => self::TYPE_STRING),
'ebl_request' => array('type' => self::TYPE_STRING),
'ebl_response' => array('type' => self::TYPE_STRING),
'created_at' => array('type' => self::TYPE_STRING),
'updated_at' => array('type' => self::TYPE_STRING),
//Multilanguage Fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 250),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 250),
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 250),
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 250),
)
);
In BO under "Eblpayment" Tab I have the following list, but I can not Edit, Update, Delete.
When I click on Edit link I got - "EblPaymentModel model not found" error:
Please someone give me some well documented resource link for developing admin module with "Admin Tab", "record list page with Edit, Update, Delete actions".
Thanks in advance.
You need a require_once 'path_to_your_model_file' on top of this controller file.
List rendering doesn't use model classes, that's why you don't get any errors but View/Edit do use it.
You also need to define $this->fields_form array for View/Edit in the __construct() method.
Have a look at documentation or native admin controllers for proper definition.
Row buttons are added like this.
$this->addRowAction('edit');
$this->addRowAction('update');
$this->addRowAction('delete');
$this->addRowAction('whatevernameyouwant');
To load a page or process something (saving to DB or whatever) for example when clicking 'whatevernameyouwant' you'd use postProcess(), processWhatevernameyouwant() and renderView() methods.
public function postProcess() {
if (Tools::getIsset('whatevernameyouwant') {
// Set display to 'view' if you want to render some content
// When display is set to 'view' the controller will call renderView() method to display content
$this->display = 'view';
// Set action if you want to process something
// When you set an action the controller will call processWhatevernameyouwant() method
$this->action = 'whatevernameyouwant';
}
return parent::postProcess();
}
public function renderView() {
// return some content related to whatevernameyouwant action
if (Tools::getIsset('whatevernameyouwant') {
return $someTemplateContent;
}
return parent::renderView();
}
public function processWhatevernameyouwant() {
// process some stuff in here
}

Create New Menu Tab In The Backoffice

I have some issues adding a new tab in the backoffice menu.
I successfully created it with this function (called inside install method of module class):
public function createMenuTab() {
$tab = new Tab();
$tab->module = $this->name;
$tab->class_name = 'AdminQuote';
$tab->id_parent = 0;
$tab->active = 1;
foreach (Language::getLanguages(false) as $l)
$tab->name[$l['id_lang']] = 'Gestione Preventivi';
return (bool)$tab->add();
}
But now I don't know how to show a view.
I put the class AdminQuoteController in /controllers/admin/AdminQuote.php and it just extends ModuleAdminController.
What should I do now to show a view? I didn't find anything in the PS docs!
There is example from smartblog module.
<?php
class AdminImageTypeController extends ModuleAdminController
{
public function __construct()
{
$this->table = 'smart_blog_imagetype';
$this->className = 'BlogImageType';
$this->module = 'smartblog';
$this->lang = false;
$this->context = Context::getContext();
$this->bootstrap = true;
$this->fields_list = array(
'id_smart_blog_imagetype' => array(
'title' => $this->l('Id'),
'width' => 100,
'type' => 'text',
),
'type_name' => array(
'title' => $this->l('Type Name'),
'width' => 350,
'type' => 'text',
),
'width' => array(
'title' => $this->l('Width'),
'width' => 60,
'type' => 'text',
),
'height' => array(
'title' => $this->l('Height'),
'width' => 60,
'type' => 'text',
),
'type' => array(
'title' => $this->l('Type'),
'width' => 220,
'type' => 'text',
),
'active' => array(
'title' => $this->l('Status'),
'width' => 60,
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
)
);
parent::__construct();
}
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Blog Category'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Image Type Name'),
'name' => 'type_name',
'size' => 60,
'required' => true,
'desc' => $this->l('Enter Your Image Type Name Here'),
),
array(
'type' => 'text',
'label' => $this->l('width'),
'name' => 'width',
'size' => 15,
'required' => true,
'desc' => $this->l('Image height in px')
),
array(
'type' => 'text',
'label' => $this->l('Height'),
'name' => 'height',
'size' => 15,
'required' => true,
'desc' => $this->l('Image height in px')
),
array(
'type' => 'select',
'label' => $this->l('Type'),
'name' => 'type',
'required' => true,
'options' => array(
'query' => array(
array(
'id_option' => 'post',
'name' => 'Post'
),
array(
'id_option' => 'Category',
'name' => 'category'
),
array(
'id_option' => 'Author',
'name' => 'author'
)
),
'id' => 'id_option',
'name' => 'name'
)
),
array(
'type' => 'switch',
'label' => $this->l('Status'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(
array(
'id' => 'active',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active',
'value' => 0,
'label' => $this->l('Disabled')
)
)
)
),
'submit' => array(
'title' => $this->l('Save'),
)
);
if (!($BlogImageType = $this->loadObject(true)))
return;
$this->fields_form['submit'] = array(
'title' => $this->l('Save '),
);
return parent::renderForm();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function initToolbar()
{
parent::initToolbar();
}
}
class BlogImageType extends ObjectModel
{
public $id_smart_blog_imagetype;
public $type_name;
public $width;
public $height;
public $type;
public $active = 1;
public static $definition = array(
'table' => 'smart_blog_imagetype',
'primary' => 'id_smart_blog_imagetype',
'multilang' => false,
'fields' => array(
'width' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
'height' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
'type_name' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
'type' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
),
);
.
.
.
}
Finally, I find this way:
I created the class AdminQuoteController in /controllers/admin/AdminQuote.php that extends ModuleAdminController. With this code inside:
class AdminQuoteController extends ModuleAdminController {
public function renderList() {
return $this->context->smarty->fetch(_PS_MODULE_DIR_.'preventivi/views/templates/admin/content.tpl');
}
}
This works even without declare display(), init(), initContent() or __construct() as I read in other previous threads.

ZF 2.3 displaying form in different modules

I'm trying to create a simple application with Zend Framework 2 and now stacked at the point of adding comments form.
I have two modules "Book" and "Comment". I want to show a form for adding comments that is disposed in module "Comment" from "Books" module controller.
The problem appears when I'm trying to open forms tag.
I'm having this error : " Fatal error: Call to undefined method Comment\Form\CommentForm::openTag()".
I tried to check $this->addComment - with var_dump and everything looks great.
Can anybody help me to solve this problem ?
<div class="row">
<div class="col-xs-12 commentBlock">
<?php
if($this->addComment){
$this->addComment->prepare();
$commentFieldset = $this->addComment->get('comment');
print $this->addComment()->openTag($this->addComment);
}
?>
</div>
</div>
Here is 'Comment' module files :
Comment\Form\CommentFieldset
<?php
namespace Comment\Form;
use Comment\Entity\Comment;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class CommentFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('comment');
$this->add(
array(
'name' => 'commentTitle',
'attributes' => array(
// 'required' => 'required',
'class' => 'form-controll',
'placeholder' => 'Введите заголовок комментария'
),
'options' => array(
'label' => 'Заголовок комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
),
)
);
$this->add(
array(
'name' => 'commentText',
'type' => 'Zend\Form\Element\Textarea',
'attributes' => array(
'required' => 'required',
'class' => 'form=-controll',
'palceholder' => 'Введите текст комментария',
),
'options' => array(
'label' => 'Текст комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
),
)
);
$this->add(
array(
'name' => 'commentType',
'type' => 'Zend\Form\Element\Radio',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => 'Тип комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
'value_options' => array(
'positive' => 'postive',
'neutral' => 'neutral',
'negative' => 'negative',
),
),
)
);
}
public function getInputFilterSpecification()
{
return array(
'commentTitle' => array(
'required' => FALSE,
'filters' => array(
array(
'name' => 'Zend\Filter\StripTags',
),
array(
'name' => 'Zend\Filter\HtmlEntities'
),
array(
'name' => 'Zend\Filter\StringTrim',
),
),
'validators' => array(
array(
'name' => 'Zend\Validator\StringLength',
'options' => array(
'min' => 1,
'max' => 250,
),
),
),
),
'commentText' => array(
'required' => TRUE,
'filters' => array(
array(
'name' => 'Zend\Filter\StripTags',
),
array(
'name' => 'Zend\Filter\HtmlEntities'
),
array(
'name' => 'Zend\Filter\StringTrim',
),
),
'validators' => array(
array(
'name' => '\Zend\Validator\StringLength',
'options' => array(
'min' => 1,
'max' => 1000,
),
),
),
),
'commentType' => array(
'required' => true,
'validators' => array(
array(
'name' => 'Zend\Validator\InArray',
'options' => array(
'haystack' => array(
'positive',
'neutral',
'negative',
),
'strict' =>\Zend\Validator\InArray::COMPARE_STRICT,
),
),
),
),
);
}
}
Comment\Form\CommentFieldset
<?php
namespace Comment\Form;
use Zend\Form\Form;
use Zend\InputFilter\InputFilter;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class CommentForm extends Form
{
public function __construct()
{
parent::__construct('comment');
$this
->setAttribute('method', 'POST')
->setHydrator(new ClassMethodsHydrator())
->setInputFilter(new InputFilter())
;
$this->add(
array(
'type' => 'Comment\Form\CommentFieldset',
'options' => array(
'use_as_base_fieldset' => true,
),
)
);
$this->add(
array(
'name' => 'csrf',
'type' => 'Zend\Form\Element\Csrf',
)
);
$this->add(
array(
'name' => 'captcha',
'type' => 'Zend\Form\Element\Captcha',
'options' => array(
'label' => 'А вы точно-приточно не робот ? ',
'captcha' => new \Zend\Captcha\Figlet(),
'attributes' => array(
'required' => true,
)
),
)
);
$this->add(
array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Добавить комментарий',
'class' => 'bigSubmit btn btn-pink',
),
)
);
$this->setValidationGroup(
array(
'csrf',
'captcha',
'comment' => array(
'commentTitle',
'commentText',
'commentType',
),
)
);
}
}
Comment\View\Helper\DisplayAddCommentForm
<?php
namespace Comment\View\Helper;
use Zend\Form\View\Helper\AbstractHelper;
class DisplayAddCommentForm extends AbstractHelper
{
public function __invoke()
{
return new \Comment\Form\CommentForm();
}
}
Book\Controller\BookController
<?php
namespace Book\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Comment\Form\CommentForm;
class BookController extends AbstractActionController
{
protected $bookModel;
protected $commentsModel;
public function showAction()
{
$isbn = $this->params()->fromRoute('num');
$book = $this->bookModel->getU(array($isbn));
$comments = $this->commentsModel->getBookComments(array($isbn));
if($_SESSION['user']){
$commentForm = new CommentForm();
} else {
$commentForm = NULL;
}
return new ViewModel(
array(
'book' => $book,
'comments' => $comments,
'addComment' => $commentForm,
)
);
}
**************
}
openTag() is method from form view helper not from your helper. In your view script change this line : print $this->addComment()->openTag($this->addComment); to this one print $this->form()->openTag($this->addComment);

Pagination not working in Yii Framework

I am using Yii Rights modules for ACL where I want pagination for Permissions page.
Following is my code:
In AuthItemController.php
public function actionPermissions() {
$dataProvider = new RPermissionDataProvider('permissions', array(
'pagination' => array(
'pageSize' => 10,
//'class' => 'CPagination', //showing an error
'itemCount' => 32
)));
// Get the roles from the data provider
$roles = $dataProvider->getRoles();
$roleColumnWidth = $roles !== array() ? 75 / count($roles) : 0;
// Initialize the columns
$columns = array(
array(
'name' => 'description',
'header' => Rights::t('core', 'Item'),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'permission-column',
'style' => 'width:25%',
),
),
);
// Add a column for each role
foreach ($roles as $roleName => $role) {
$columns[] = array(
'name' => strtolower($roleName),
'header' => $role->getNameText(),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'role-column',
'style' => 'width:' . $roleColumnWidth . '%',
),
);
}
$view = 'permissions';
$params = array(
'dataProvider' => $dataProvider,
'columns' => $columns,
);
// Render the view
isset($_POST['ajax']) === true ? $this->renderPartial($view, $params) : $this->render($view, $params);
}
And in View
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'bordered',
'dataProvider' => $dataProvider,
'template' => '{pager}{items}',
'emptyText' => Rights::t('core', 'No authorization items found.'),
'htmlOptions' => array('class' => 'grid-view permission-table'),
'columns' => $columns,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
'class' => 'CLinkPager',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
));
I have already implemented pagination for other pages by using same method but here in rights module its not working. Its not showing any error but also not displaying pagination links/buttons.
I had the same problem when implementing multiple grids in one page, the solution that worked for me was , I checked the url the grid ajax call,and before update I manipulated the url, and set the correct url and parameters before ajax request!
like:
$this->widget('zii.grid.GridView', array(
'id' => 'group-grid-customers-list-not-scheduled',
'dataProvider' => $notScheduledVisitedDataProvider ,
'beforeAjaxUpdate' => '
function(id , options)
{
options.url = options.url.split("&test=test&");
options.url = options.url[0] + "&test=test&" + $(".search-form form").serialize();
}',
'columns' => array(
'col1',
'col2',
'col3',
),
));

Categories