I'm having two modules.
custom footer.
Testimonial.
Now I'm trying to display testimonial module inside custom footer. Like another stackoverflow post I have added
// Display testimonial part
$this->data['testimonial_block'] = $module = $this->getChild('module/testimonial', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80
));
in "catalog/controller/common/customfooter.php" before $this->render ();
And added <?php echo $testimonial_block; ?> inside customfooter.tpl
After adding this i'm getting this error
Notice: Undefined index: testimonial_title in C:\xampp\htdocs\magichomegym\catalog\controller\module\testimonial.php on line 6
Notice: Undefined index: testimonial_limit in C:\xampp\htdocs\magichomegym\catalog\controller\module\testimonial.php on line 22
Did anyone knows where i'm going wrong?
You need to supply the relevant data in the array
$this->data['testimonial_block'] = $module = $this->getChild('module/testimonial', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80,
'testimonial_title' => 'Title here',
'testimonial_limit' => 5,
));
Replacing the 5 with the amount of testimonials you want to display and the 'Title here' with whatever you want the title to be
Related
I am running into a little snag with combining extensions "EchMultiSelect" and "MultiModelForm" of YII framework.
What I'm trying to do is copy a set of form elements one of which elements is an EchMultiSelect widget.
According to tutorial on the jqRelCopy page, I would need to pass a copy of the element (datePicker in their example) to the 'jsAfterNewId' option:
'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),
So, I tried to modify that to:
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
Where I also added the following to MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if(this.attr('multiple')=='multiple'){this.multiselect(jQuery.extend({$jsOptions}));};";
}
its copied and working properly when i am using Add Person link but what happens if i am adding/cloning three items for example and when i change the third item multiselct option then its reflecting to the first multiselect dropdown only this is same for other as well also when i am adding new items by clicking on the Add Person link then its cloning the same element to the new row item
here is the code for the form configuration variables and multimodel widget call.
//$userList=array of the userIds from users table
$memberFormConfig = array(
'elements'=>array(
'userId'=>array(
'type'=>'ext.EchMultiSelect.EchMultiSelect',
'model' => $User,
'dropDownAttribute' => 'userId',
'data' => $userList,
'dropDownHtmlOptions'=> array(
'style'=>'width:500px;',
),
),
...
...
));
calling the MultiModelForm widget from the same view file
$this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_member', //the unique widget id
'formConfig' => $memberFormConfig, //the form configuration array
'model' => $model, //instance of the form model
'tableView' => true,
'validatedItems' => $validatedMembers,
'data' => Person::model()->findAll('userId=:userId', array(':userId'=>$model->id)),
'addItemText' => 'Add Person',
'showAddItemOnError' => false, //not allow add items when in validation error mode (default = true)
'fieldsetWrapper' => array('tag' => 'div',
'htmlOptions' => array('class' => 'view','style'=>'position:relative;background:#EFEFEF;')
),
'removeLinkWrapper' => array('tag' => 'div',
'htmlOptions' => array('style'=>'position:absolute; top:1em; right:1em;')
),
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
));
Can someone help me with this please?
Thanks in advance!
After a long searching and googleing i found the solution for this, just replace the function in your MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if ( this.hasClass('test123456') )
{
var mmfComboBoxParent = this.parent();
// cloning autocomplete and select elements (without data and events)
var mmfComboBoxClone = this.clone();
var mmfComboSelectClone = this.prev().clone();
// removing old combobox
mmfComboBoxParent.empty();
// addind new cloden elements ()
mmfComboBoxParent.append(mmfComboSelectClone);
mmfComboBoxParent.append(mmfComboBoxClone);
// re-init autocomplete with default options
mmfComboBoxClone.multiselect(jQuery.extend({$jsOptions}));
}";
}
Thats It....!!
Thanks...!!!
I'm trying to use robregonm pdfresponseFormatter to create a PDF, problem is, the pdf class is never called as the format reponse type.
'response' => [
'formatters' => [
'html' => [
'class' => 'yii\web\HtmlResponseFormatter',
],
'pdf' => [
'class' => 'robregonm\pdf\PdfResponseFormatter',
'mode' => '',
'format' => 'A4',
'defaultFontSize' => 0,
'defaultFont' => '',
'marginLeft' => 15,
'marginRight' => 15,
'marginTop' => 16,
'marginBottom' => 16,
'marginHeader' => 9,
'marginFooter' => 9,
]
]
],
....
$file = $this->getPdf($report);
....
private function getPdf($report){
Yii::$app->response->format = 'pdf';
Yii::$container->set(Yii::$app->response->formatters['pdf']['class']);
$this->layout = '//attachment';
return $this->render('pdf/actionplan', ['model' => $report]);
}
the $file variable has the HTML text in it from the view
You are asking the wrong question. Of course $file has HTML in it, you are returning HTML from your view.
Yii::$app->response->format = 'pdf';
works when the controller returns a response to the browser.
What you want to ask is why the controller function (I hope this is in a controller) does not return a PDF created from the HTML.
If you just want to save a PDF look how I handle this: https://github.com/Mihai-P/yii2-core/blob/master/components/Controller.php in the actionPdf function. That function returns a file that you can save on the server if you want.
Unfortunately I've not been able to get this extension to work. I did get kartik pdf to work great
I recommend using the kartik extension instead.
I have created a method in my model that successfully displays the correct data when I pr($variable) to the screen. However without the print I am receiving the 'Notice (8): Undefined variable' message.
The model in question 'industry' has many 'news and events'.
What I'm trying to do in the view for a specific industry is display news that is of two different conditions. One type of news is news.type = highlight(displaying just one highlight story), and the second is a list of active stories.
This is the method in my model.
// industry highlight news
public function getHighlightNews() {
$newsHeadline = $this->News->find('first', array(
'conditions' => array('News.type' => 'highlight','News.active' => 'yes'),
'limit' => 1,
'recursive' => 0,
'fields' => array(
'News.slug',
'News.title',
'News.date',
'News.imgPathThumb',
'News.alt_tag',
'News.id',
'News.caption',
'News.body'
),
));
return $newsHeadline;
}
public function getNewsList() {
$newslist = $this->News->find('all', array(
'conditions' => array('News.active = "Yes"','News.industry_id = 1'),
'limit' => 4,
'recursive' => 0,
'fields' => array(
'News.slug',
'News.title',
'News.date',
'News.industry_id',
'News.imgPathThumb',
'News.alt_tag',
'News.id',
'News.caption',
'News.body'
),
));
return $newslist;
}
And this is what is in my industry controller. I've created similar model methods for the news list and event lists.
public function view($id = null) {
$this->layout='default';
$this->Industry->id = $id;
if (!$this->Industry->exists()) {
throw new NotFoundException(__('Invalid industry'));
}
$eventlist = $this->Industry->getEventsList($id);
$newslist = $this->Industry->getNewsList($id);
$highlights = $this->Industry->getHighlightNews($id);
//pr($newslist); die;
$this->set('eventlist', $eventlist, 'newslist', $newslist, 'highlights', $highlights);
}
And this is my view:
<div class="first articles">
<?php foreach ($highlights as $highlight): ?>
<h1><?php echo $highlight['Industry']['title']; ?></h1>
<p><?php echo $highlight['Industry']['body']; ?>
<?php endforeach; ?>
</p>
</div><!-- /articles -->
the message I get in the view is:
Notice (8): Undefined variable: highlights [APP\View\Industries\view.ctp, line 12]
Warning (2): Invalid argument supplied for foreach() [APP\View\Industries\view.ctp, line 12]
I suspect it's something small I'm overlooking.
Thanks, Paul
Setting variables doesn't work like that. You need to change this:
$this->set('eventlist', $eventlist, 'newslist', $newslist, 'highlights', $highlights);
To this:
$this->set('eventlist', $eventlist);
$this->set('newslist', $newslist);
$this->set('highlights', $highlights);
Or this:
$this->set(compact('eventlist','newslist','highlights'));
I have a category model with this structure:
id,name,parent_id
I want to display categories in a treeview in Yii. As I found there is a widget called 'CTreeView' but I cannot find an clear example how to use it.
Pleas help me.
Yes, there is not much tour for CTreeView. But You can look here
http://www.yiiframework.com/wiki/?tag=ctreeview
Generating tree from database in Yii
http://www.yiiplayground.com/index.php?r=UiModule/ui_other/treeView
1. Download Extension
Download AIOTree
2. Extract it & put in your extension directory of yii project(extension/AIOTree/your extract files)
3. Now add this code at any where you want
<?php
$data=array(
'1'=>array('parentid'=>'','text'=>'One'),
'2'=>array('parentid'=>'','text'=>'Two'),
'3'=>array('parentid'=>'','text'=>'Three'),
'11'=>array('parentid'=>'1','text'=>'One-One'),
'12'=>array('parentid'=>'1','text'=>'One-Two'),
);
// AIOTree
Yii::import("application.extensions.AIOTree.*");
$this->Widget('AIOTree',array(
'data'=>$data,
));
?>
You can create array with your data from database and use it in CTreeView widget
// Your array with data
$data = array(
array(
'text' => 'Node 1',
'expanded' => true, // expanded branch or not (true by default)
'children' => array(
array('text' => 'Node 1.1'),
array('text' => 'Node 1.),
array('text' => 'Node 1.3')
)
),
);
// In your view call widget
$this->widget('CTreeView', array('data' => $data));
See more widget capability in offical documentatio: (http://www.yiiframework.com/doc/api/1.1/CTreeView)
I am having problem with yii tokeninput extension. When i search name it gives the user list and if i select any name and if that name is also selected previous than the cursor point after the selected item, it does not point at the end of all the the item in the input box.
I am using this configuration.
$this->widget('ext.tokeninput.TokenInput', array(
'model' => $model,
'attribute' => 'USER_ID',
'url'=>$this->createUrl('user/searchUserNames'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
// 'resultsFormatter' => 'js:function(item){ return “<li><p>” + item.name + “</p></li>” }',
'theme' => 'facebook',
//'hintText' => 'Type',
'prePopulate' => $prePopulate,
'processPrePopulate' => $processPrePopulate,
)
));
I have also lookout at the examples but does not find the solution. can any one help me ?
Loopj: jquery token input demo
plz comment the line number 509 in **jquery.tokeninput.js**
input_token.insertAfter(found_existing_token);
that line insert cursor after that selected item so if you comment
this line cursor is at the end of all names