Add Custom Row action in Prestashop ModuleAdminController - php

I want to add a download button for each row in moduleadmincontroller helper.
I tried to add it by using the following code on RenderList function. But it is not working.
$this->addRowAction('download');
Kindly let me know if I can add custom action for each row and how to process it.

as you know the actions is the default array that have default value array('view', 'edit', 'delete', 'duplicate'); and you can use this but if you want add new action you should use some function.for example you can go to your_prestashop/controllers/admin/AdminRequestSqlController.php
this class add new action with 'export' name
$this->addRowAction('export');
then for create link for this action it is using the displayExportLink() function as you can see in bellow code
public function displayExportLink($token, $id)
{
$tpl = $this->createTemplate('list_action_export.tpl');
$tpl->assign(array(
'href' => self::$currentIndex.'&token='.$this->token.'&
'.$this->identifier.'='.$id.'&export'.$this->table.'=1',
'action' => $this->l('Export')
));
return $tpl->fetch();
}
and then you can get your new action with the initProcess() function or initcontent() function and do something lik download
public function initProcess()
{
parent::initProcess();
if (Tools::getValue('export'.$this->table))
{
$this->display = 'export';
$this->action = 'export';
}
}

Related

Zend Form getValues() doesn't work

I'm trying to create simple form with Zend, I need to use this form in most part, so I create the default form then in controller i modify it for the occurrence with private function. But I have two problems:
the form getValues() doesn't take the value of text element.
I put render at the end of the form action, but it doesn't render to the right page.
The form consists of a text field and the sumbit button
Here is the code of my controller:
That is for customize the form
private function getSearchForm($action = '', $name, $type, $placeholder)
{
$urlHelper = $this->_helper->getHelper('url');
$this->_searchForm = new Application_Form_Admin_Search_Search();
$this->_searchForm->setName($name);
$text = $this->_searchForm->getElement('ricerca');
$text->setLabel('Ricerca '.$type);
$text->setName($type);
$text->setAttrib('placeholder', $placeholder);
$this->_searchForm->setAction($urlHelper->url(array(
'controller' => 'admin',
'action' => $action),
'default'
));
return $this->_searchForm;
}
there are the actions:
public function pneumaticoAction()
{
$this->_searchForm = $this->getSearchForm('pneumaticosearch', 'search', 'pneumatico', 'Ricerca per: modello, marchio o codice');
$this->view->searchForm = $this->_searchForm;
}
public function pneumaticosearchAction()
{
if (!$this->getRequest()->isPost()) {
$this->_helper->redirector('index', 'public');
}
$form=$this->_searchForm;
if (!$form->isValid($this->getRequest()->getPost())) {
$this->render('pneumatico');
}
$values = $form->getValues();
$this->view->assign(array(
"pneumatici" => $this->_modelAdmin->searchPneumatici($values['pneumatico'])
));
$this->render('pneumatico');
}
First question, whenever you get routed to pneumaticosearch action, you do not set $this->_searchForm but you have it as:
$form=$this->_searchForm;
Should be something like this:
$form = $this->getSearchForm('pneumaticosearch', 'search', 'pneumatico', 'Ricerca per: modello, marchio o codice');
And the second question. When you run render, it is similar to pass $this->view parameters to .phtml. I don't see your view files, but I guess you need to set view first:
$this->view->searchForm = $form

Call another action from one action of the same controller

I am new to YII. How to call an action from another action of the same controller.
Suppose I am in action A. I need to call action B with two parameters. My controller name is Master Controller. How will I perform this. Please say me a solution. Thanks in advance.
My controller:
class NimsoftController extends Controller
{
public function actionStore_action($action,$data_id)
{
$model= new NimsoftUserLoginAction;
$model->user_id=Yii::app()->user->id;
$model->action=$action;//"Deleted";
$model->affected_data_id=$data_id;//"22";
$model->save();
}
public function actionSearch($id)
{
$cust_id = $id;
$criteria = new CDbCriteria();
$criteria->condition = "host_customer_id = '$cust_id'";
$details = NimsoftHost::model()->find($criteria);
$criteria2 = new CDbCriteria();
$criteria2->condition = "cust_id= '$details->host_customer_id'";
$name = MasterCustomers::model()->find($criteria2);
$dataProvider = new CActiveDataProvider('NimsoftHost', array(
'criteria' => $criteria,
'pagination'=>array('pageSize'=>40)
));
$model = new NimsoftHost();
$this->actionStore_action(array('action'=>'search', 'data_id'=>$cust_id));
$this->render('index',array(
'dataProvider' => $dataProvider,
'details' => $details,
'name' => $name->cust_name,
'model' => $model
));
}
}
You can simply call the function directly, or,
$this->actionMyCustomAction(); exit;
you can perform a redirect to the action:
$this->redirect('anotherControllerName/myCustomAction');
or this if you are in the same controller:
$this->redirect('myCustomAction');
UPDATE:
You are passing the variables wrongly:
$this->actionStore_action(array('action'=>'search', 'data_id'=>$cust_id));
It should be two separate variables:
$this->actionStore_action('search', $cust_id);
This has NOTHING to do with Yii. It's only basic function calling.
$this->forward('site/contact');
In case of forward your URL will not be change and you cannot send extra parameter in this.
If you want to send extra parameter then use redirect.
$this->redirect(Yii::app()->createUrl('site/contact', array('id' => '22')));
Hope this will help you..
You can do it this way also:-
Now you want to call action Name1 inside action Name2.
public function actionName1($param1,$param2) {
//your code...
}
public function actionName2() {
$this->redirect(array('name1','param1'=>'param1','param2'=>'param2'));
}
In case of forward your URL will not be change and you cannot send extra parameter in this.
$this->redirect('contact');

show html option value codeigniter

I'm new in Codeignite. I have a "Test" Controller with "index()" and "view($id)" functions. the index method goes to "test1.php" view. In "test1.php", I have a dropdown options. if I submit on this page, the "view" method of "Test" Controller will be called. My question is how can I pass the option value to "view" function , so that the argument of method will be set to the option value and then the url would be something like "http://localhost/test/view/id" which the id is option value from "test1.php"
Test Controller
class Test extends CI_Controller{
public function indx() {
//some code
$this->load->view('test1.php');
}
public function view($id)
{
//some code, here I use $id which I want to be option value from test1.php
}
test1.php
<?php
$options = array(
'1' => 'One',
'2' => 'Two',
'3' => 'Three',
'4' => 'Four',
);
$js = 'id="shirts" onChange="this.form.submit();"';
echo form_dropdown('shirts', $options, '1', $js);
/* here I want to call echo form_open() as echo form_open("/test/view/[option value]") but I don't know how to do this;*/
You can load view with data.
class Test extends CI_Controller{
public function index($id) {
$this->data['result'] = get_results($id);
$this->load->view('test1.php', $this->data);
}
}
In the view file:
foreach ($results as $result) {
// action
}
If its essential that you pass the ID in the URL then you'll need to use javascript to append the ID to the form action URL using a change event listener on the select field.
However, IMHO, you would be better off just retrieving the value within the view() method from the POST data.
Using $id = $this->input->post('shirts', TRUE), rather than forcing it through the URL.

Magento : add custom button to an admin form

Building a custom adminhtml module. Im using a simple form. it looks like this :
<?php
class Namespace_Modulename_Block_Adminhtml_Modulename_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('modulename_form',array('legend'=>Mage::helper('modulename')->__('Module Data')));
$fieldset->addField('test', 'text', array(
'label' => Mage::helper('modulename')->__('Test'),
'name' => 'test',
));
// I want to add a custom button here. Say an action called "Add Option".
//Clicking this action adds input boxes or dropdowns to the form that are to
//to be included in the post when submitting the form (obviously).
I have been looking for a solution on Stack overflow and have not been able to find something that could help. I have then tried searching for something similar present in the Mage Core.
In the admin panel, if i go to [Catalog->Attributes->Manage Attributes] and click on a standard attribute like "Manufacturer" for example, on the second tab, called "Manage labels/Options" i see the following screen :
There is a button and action which allows me to add options (in the form of textboxes) to the form. Identifying this as something i am trying to replicate, i went into the core to try and figure out what to do. If i open the following files (Magento Enteprise 12.0.2) :
Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options
I see it is empty, but extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
and I have gone through this file, but little makes sense to me. Am I going down the wrong way? How can I achieve something similar, a button and action which adds fields to a admin form?
thanks
You can set custom template for your form, and add there any tags (like button) via html.
You can add renderer for you field
$customField = $fieldset->addField('test', 'text', array(
'label' => Mage::helper('modulename')->__('Test'),
'name' => 'test',
));
$customField->setRenderer($this->getLayout()->createBlock('yuormodule/adminhtml_yourform_edit_renderer_button'));
in Block Class
class Yournamespace_Yourmodule_Block_Adminhtml_Yourform_Edit_Renderer_Button extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface {
public function render(Varien_Data_Form_Element_Abstract $element) {
//You can write html for your button here
$html = '<button></button>';
return $html;
}
}
1- First you must create a container for your Grid like this
public function __construct() {
parent::__construct();
$this->setTemplate('markavip/dataflow/edit/form/mapping.phtml');
}
2- in the Same Container you will add your buttons like
public function _prepareLayout() {
$this->setChild('add_button', $this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('markavip_dataflow')->__('Add Option'),
'class' => 'add',
'id' => 'add_new_option_button'
)));
$this->setChild('delete_button', $this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('markavip_dataflow')->__('Delete'),
'class' => 'delete delete-option'
)));
return parent::_prepareLayout();
}
public function getAddNewButtonHtml() {
return $this->getChildHtml('add_button');
}
public function getDeleteButtonHtml() {
return $this->getChildHtml('delete_button');
}
3- and in the PHTML you will add thes buttons like this :
<?php echo $this->getAddNewButtonHtml() ?>
and after this you will play in JS functions for add and hide

How to Retrieve Image Files from Database Using Yii Framework?

Our Yii Framework application has the following defined as part of the UserProfileImages model:
public function getProfileImages($param, $user_id) {
if(isset($param['select']) && $param['select']=='all'){
$profile_images = UserProfileImages::model()->findAllByAttributes( array( 'user_id'=>$user_id) );
} else {
$profile_images = UserProfileImages::model()->findByAttributes( array( 'user_id'=>$user_id) );
}
return $profile_images;
}
How would I wire up the above snippet to a widget in my view to return all the images for a given user?
Bonus Question: Which image rotator do you suggest to render the above?
In your view file, add something like this, assuming that your controller specified $user_id:
$this->widget('UserProfileImagesWidget', array(
"userProfileImages" => UserProfileImages::getProfileImages(
array("select" => "all"),
$user_id
),
"user_id" => $user_id
));
Depending on your MVC philosophy, you could also retrieve the userProfileImages data in the controller and pass that data to your view.
Define a widget like this:
class UserProfileImagesWidget extends CWidget {
public $user_id;
public $userProfileImages = array();
public function run() {
$this->render("userProfileImage");
}
}
Finally, in the userProfileImages.php view file, you can do something like this:
if(!empty($this->userProfileImages)) {
// Your display magic
// You can access $this->user_id
}
As a side note: You might want to change the order of your parameters in getProfileImages. If $user_id is the first parameter, you can leave out $params completely in case you don't want to specify any.

Categories