I have a Yii Layout, called Main, it loads all the CSS and the JavaScript, correctly ordered.
So, i have two views, one just have pure HTML, and the other one have something like this :
<?php
$dataProvider=new CActiveDataProvider('agenda');
$dataProvider->pagination->pageSize=5;
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'enablePagination'=>true,
'itemView'=>'_agenda', // refers to the partial view named '_agenda'
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'cssFile'=>'css/my.css',
),
));
?>
My problem :
The second one throw this exception Undefined is not a function and aim to the line with $(document).foundation(); in the code.
Is the only error it throws, and both have the same JavaScripts and CSS imported.
They are incompatible?
Solved, i just had conflicts with the Foundation's jQuery and Yii's jQuery.
The solution is just use this at top :
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
Remove others jQuery and move the foundation.min.js to the bottom.
Related
I use Yii 1.1.14
I use form to capture an email, not using Yii ajaxValidation/clientValidation
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'form-newsletter',
'action' => null,
'focus' => array($model, 'email'),
'htmlOptions' => array(
'role' => 'form',
),
)); ?>
I got this at js console
Uncaught TypeError: undefined is not a function
Which is refer to this
jQuery('#form-newsletter').yiiactiveform({'validateOnSubmit':true,'validateOnChange':true,'errorCssClass':'has-error has-feedback','successCssClass':'has-success has-feedback','inputContainer':'div.form-group','attributes':[{'id':'NewsletterForm_email','inputID':'NewsletterForm_email','errorID':'NewsletterForm_email_em_','model':'NewsletterForm','name':'email','enableAjaxValidation':true,'clientValidation':function(value, messages, attribute) {
I also check that jquery.yiiactiveform.js is present.
The question is, i dont want to use the default ajaxValidation/clientValidation, why is it loaded? and why it tells that yiiactiveform is undefined?
Thank you.
Check if you are including a newer version of jQuery than the one Yii includes (2.x for example) for the validation.
If you use other custom javascripts then must use in your layout code for example:
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/bootstrap.min.js');
I am dealing with the CGridView widget in Yii. I've customized most of it, but can't seem to customize the icons that appear when you click on the column headers to sort the data. (little arrows that point either up or down depending on the sort order) Also, the icons are completely gone after adding in the 'columns' option. A portion of the code in my view is below:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager' => array('cssFile' => '/css/myCss.css'),
'cssFile' => '/css/myCss.css',
'summaryText' => 'Showing {start} - {end} of {count} data rows.',
'htmlOptions' => array('id' => 'grid'),
'columns' => array(
array(
'name' => 'name',
'value' => '$data->name',
),
array(
'name' => 'description',
'value' => '$data->description',
),
array(
'name' => 'date',
'value' => '$data->date',
),
),
));
?>
Yii's documentation isn't clear at all on this and there doesn't seem to be anyone (that I could find) that also has this issue.
->Also, a related question:
How would I make each row an anchor link? I need each row to be a link to view the details about the clicked row. I know that cgridview provides view, edit, and delete links at the end of the row if told to, but is it possible to get the entire row to be a single anchor link? I know how to do this manually in html, but don't know how to do this inside cgridview.
If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid.
In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:
'columns'=>array(
...
array(
'name'=>'name',
'value'=>'CHtml::link($data->name, "#myAnchor")',
'type'=>'html'
),
...
)
I am not sure what version of Yii you're working on, but let's try this code
<?php
'columns' => array(
array(
...
'type' => 'html',
'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),
My problem: the two pagination options are on separate lines.
I have:
<div class="search_result searchconright">
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'dataProvider' => $model->search(),
'itemView' => '_index_post',
'enablePagination' => true,
'pager' => array(
'cssFile' => Yii::app()->baseUrl . '/css/clistview.css',
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'summaryText' => '',
'sortableAttributes' => array(
),
));
?>
</div>
<div class="pagetxt">
<span>View</span>
<a class="page_search_limit">All</a>
<a class="page_search_limit page_search_limit_active">3</a>
<a class="page_search_limit page_search_limit_active">5</a>
<a class="page_search_limit page_search_limit_active">24</a>
<a class="page_search_limit">48</a>
</div>
and i would like to insert the entire html from class pagetxt in the widget, because the seccond pagination, is under the widgets pagination; i would like them to be on the same line
also, other suggestions are welcomed
the pagination:
You have 2 options, first the way you are doing it, you can use the template property of CListView, to add the HTML where you want inside the widget.
But It looks like what you are trying to do, is to allow the user to specify the number of elements they want to see per page, so I'd recommend to use something like the PageSize extension
I think you can do this with CSS:
.search_result, .pagetxt {
display: inline-block;
}
To change the CListView pagination HTML, you would have to create a new CLinkPager and the pass parameters to it. So I think CSS is way simpler :)
This is purely a layout issue: you need to have the pager render inline with your custom HTML.
One way to do that would be to give display: line-block to both of these DIVs with CSS, but of course you can also use other techniques like floating.
You can easily target the stock pager by setting the pagerCssClass property on your list view; the default is simply "pager", so you could do
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'pagerCssClass' => 'pager pager-inline'
// ...
);
and then for example
.pager.pager-inline, .pagetxt {
display: inline-block;
}
Controller :
Yii::import("xupload.models.XUploadForm"); //enciora
$photos = new XUploadForm;
$this->render('create', array(
'model' => $model,
'photos' => $photos
));
create: <?php echo
$this->renderPartial('_form',
array(
'model'=>$model,
'photos' => $photos
)); ?>
_form: <?php
$this->widget( 'xupload.XUpload', array(
'url' => Yii::app()->createUrl( "/encionmentDetail/upload"),
//our XUploadForm
'model' => $photos,
//We set this for the widget to be able to target our own form
'htmlOptions' => array('id'=>'encionment-detail-form'),
'attribute' => 'file',
'multiple' => true,
//Note that we are using a custom view for our widget
//Thats becase the default widget includes the 'form'
//which we don't want here
'formView' => 'application.views.encionmentDetail._form',
)
);
?>
ERROR: Undefined variable: model or Undefined variable: photos . this are the errors coming
while creating. if one model is passed then it shows properly. Please help
Well, the problem is with this line 'formView' => 'application.views.encionmentDetail._form'
. if i remove this line then no error. what should i do ?
This could well be due to the fact that your _form and your inner form for
'formView' => 'application.views.encionmentDetail._form',
are the same. Use a different one in the form view. Its kind of getting recursive.
in controller file :-
<?php
Yii::import("xupload.models.XUploadForm");
$photos = new XUploadForm;
$this->render('create', array(
'photos' => $photos,
));
?>
in create a file passing a bot model in render file :-
<?php echo $this->renderPartial('_form', array('model'=>$model,'photo'=>$photo))
Important note : must same a active from id and extensition html option id
snow_walker absolutely right, but I want to give details.Well, maybe it will help someone.
Such case occurs when xupload widget view contains <form>, so when it renders it becomes nested in CActiveForm.
One of the way to fix it:
Place CActiveForm widget in create.php
Copy everything from standard xupload form view (…\protected\extensions\xupload\views\form.php) to your model _form.php (…\protected\views\somemodel_form.php)
Delete from _form.php
<?php if ($this->showForm) echo CHtml::beginForm($this -> url, 'post', $this -> htmlOptions);?>
and
<?php if ($this->showForm) echo CHtml::endForm();?>
The other thing is that you cannot change the attribute's value in the widget configuration. It has to be 'file' in the other way the Internal Server Error (500) occurs.
I got a insert form. I would like to insert the below code into the form.
<?php
echo $html->image("slide_03.jpg", array(
"alt" => "Event Banner",
'class' => '',
));
?>
In my view layer I want the the image to be display. However, the image did not display and got this code in my view layer instead
image("slide_03.jpg", array( "alt" => "Event Banner", 'class' => '', )); ?>
In CakePHP 2.x you have to use $this->Html->image(). $html->image() was used in previous CakePHP versions and no longer works in CakePHP 2.x.
In general (not just for images) you can set option after or before if you want additional html elements near of your input element.
As you see from sample below you can combine input options with $this->Html->image().
<?php
echo $this->Form->input('field', array(
'before' => $this->Html->image(),
'after' => $this->Html->image(),
));
More details about options on documentation.