Yii: loading css and js files when calling another controller - yii

In my html code I'm calling another controller like this:
<a class='objName' href='".CController::createUrl('/mobilechart/index')."'>$dd->name</a>
When this controller is loaded it doesn't charge the css and js files, I can see the content but not in the correct style or correct working, but if I refresh the page it does it. Why is this happening?
I'm not sure if this helps but also the first time it charges (when css and js files are not loaded) the "yii-debug-toolbar-switcher" is working and when the page is properly loaded it doesn't!
I load the css and js files using:
<?php Yii::app()->clientScript->registerCssFile
<?php Yii::app()->clientScript->registerScriptFile
Thank you very much!

Try the following code for the link:
<?php
echo CHtml::link(
$dd->name,
array( '/mobilechart/index' ),
array( 'class' => 'objName' )
);
?>
Also, make sure that both your controllers are using the same layout. Or if they're using different layouts, make sure that you register the CSS and script files in both layouts.

Try this Register client script, css in Yii

Related

YII1 how to set "anchor" for putting Jquery code there

Now I am working with one old system Which were developed with using YII 1 framework.
Yii1 form using some jquery code for form validation and put this code at the end before </body> tag.
I need to make YII1 form to put its validation code a bit above because at the end (before </body> tag) I have my js code.
In Yii2 It is easy to make by using some anchor like this
$this->endBody()
Is There any Way in Yii1 to set up place in layout to put JS code into that place ?
Thanks in advance
You just add your js file like this in content section or in your html form:
<script src="<?=Yii::app()->theme->baseUrl; ?>/js/bootstrap.min.js"></script>

Manual Positioning of Shareaholic ShareBar Plugin

I'm trying to manually position the Shareaholic sharebar WP plugin. I am using a vertical one, and want it to be in a fixed position on the left side of my screen beside my main content area. So far I have figured out how to get it onto my site, but not able to position it. I'm referencing this post of someone who tried to do a similar thing.
I'm using this code to insert it into my single.php
<?php echo do_shortcode('[shareaholic app="share_buttons" id="4766761"]'); ?>
But haven't had any luck with getting css positioning to work, or where exactly to put it in my single.php file
Right now it's just below this code :
<main class='content units <?php avia_layout_class( 'content' ); ?>' <?php avia_markup_helper(array('context' => 'content','post_type'=>'post'));?>>
And it's showing up above the post content.
Any suggestions?
Many thanks
Jonny
Custom CSS should be added to your styles.css theme file, but it is recommended to create a child theme when making any adjustments within your theme so that you will not run the risk of losing your customization if/when your theme releases a new version and you update.

MVC helper inside a template

I am trying to use a kendo MVC helper inside a template (remote template file loaded like: http://docs.kendoui.com/howto/load-templates-external-files#remote-templates. I have a controller that sends to the client the generated markup)
My template file is something like:
<script id="my-pager-template" type="text/x-kendo-template">
My pager
#(Html.Kendo().ListView<Business.Data.MyPage>()
.Name("myPagerListView")
.TagName("div")
.ClientTemplateId("my-pager-item-template")
.DataSource(dataSource => dataSource.Read(read =>
read.Action("GetMyPages","Page")
)
).ToClientTemplate())
</script>
<script id="my-pager-item-template" type="text/x-kendo-template" >
<div class="k-button" data-pager-item-pageid="${PageID}" data-pager-item-pagename="${Name}">
<span>${ButtonText}</span>
</div>
</script>
But the generated markup is giving me an Uncaught SyntaxError: Unexpected token < in my browser console (chrome).
The markup generated by the helper is like this:
<div id="myPagerListView"></div>
<script>
jQuery(function(){jQuery("\#myPagerListView").kendoListView({"dataSource":{"transport":{"prefix":"","read":{"url":"/Page/GetMyPages"}},"serverPaging":true,"serverSorting":true,"serverFiltering":true,"serverGrouping":true,"serverAggregates":true,"type":"aspnetmvc-ajax","filter":[],"schema":{"data":"Data","total":"Total","errors":"Errors","model":{"fields":{"PageID":{"type":"number"},"Name":{"type":"string"},"ButtonText":{"type":"string"}}}}},"template":kendo.template($('\#my-pager-item-template').html())});});
<\/script>
</script>
Can I use kendo helpers this way?
(In this post, it says that it can be used: Can I use Kendo MVC helpers inside templates?)
I got that message a lot of times, your code is fine, the problem comes retrieving the data, kendo deserialize what it recieves from read.Action("GetMyPages","Page"), you probably are retrieving an HTML page instead of a json, so it tries to serialize something like "<html ...." and here you got the error, just check the url on chrome to check if you recive an json
i mean check http://yourdomain.com/Pages/GetPages/ (or the routing according to your app), you probably get an HTML page
I had this exact issue also. I have come to realise (over the past 3 hours :( ) that this is because I was using ajax then the jquery html function to load the template file and that the error was happening with in jquery's function as it tried to parse than execute the template file which has been mangled for an unknown reason by kendo. (escaping that script tag and in my case inserting buttons in that space). Fortunatly when kendo Its self tries to use the template it does work.
To get around this problem I rendered the partial view directly on the page.
Hope this helps.

Datetimepicker shows up in a 'naked' way

I want to set up both date and time in a custom field (Yii).
For this i've chosen this datetimepicker.
But as i've loaded it into protected/extentions it now works, but its outlook is somehow 'naked'. I've rounded datepicker's appearence in red.
Its configuraition is:
<?php $form->widget ('ext.CJuiDateTimePicker.CJuiDateTimePicker',
array (
'attribute'=>'start',
'model'=>$model,
'value' => $model->start,
'language' => 'en',
'options'=>array (
// 'timeFormat'=>strtolower(Yii::app()->locale->timeFormat),
'showSecond'=>true,
),
)
); ?>
How to fix it? Am i missing some skin files? How to get them?
I use bootstrap theme FYI.
This is a styling issue .
Download correct Style.css file it will show datepicker correctly .
The issue was that in the Yii app development i was using the NlsClientScript Yii Extention for preventing duplicate scripts loading. So, the datatimepicker's css file has not been loaded into the current nlsXXXXXXX.css file. It turned that this NlsClientScript does manage/aggregate the css files load, the docs saying opposite though...
From documentation:
The extension does not prevent the multiple loading of CSS files.
So I've found the corresponding file, deleted it and reloaded the app.
From documentation:
The extension doesn't watch wether a js/css file has been changed. If you set the merge functionality and some file changed, you need to delete the cached merged file manually, otherwise you'll get the old merged one.

How add CJuiDatePicker in JQRelcopy on Yii Framework

I have a problem with CJuiDatePicker in the module JQRelcopy on Yii framework.
I use this module as I have a form with a datepicker field to be copied as many times as the user wishes.
The module works fine if I put a normal field (without datepicker), but as soon as I add the module CJuiDatePicker which is also a module of the Yii framework, I have a blank page appears. I followed the following tutorial: http://www.yiiframework.com/extension/jqrelcopy/ explains the integration jqrelcopy in a form containing CJuiDatePickerm, which is exactly what I need.
I study the problem and I saw that it was when I Atoute the following line in the properties of my widget JQRelcopy the problem occurs:
'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),
in
$this->widget('ext.jqrelcopy.JQRelcopy', array(
'id' => 'copylink',
'removeText' => 'remove',
//add the datapicker functionality to the cloned datepicker with the same options
'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),
));
I look in several forums and anywhere a person has had the same problem as me.
The only way I could do this in the past, was ditching the CJuiDatePicker and using the on method of JQuery.
$('body').on('focus', '.idata', function(){
jQuery(this).datepicker(
jQuery.extend(
{showMonthAfterYear:false},
jQuery.datepicker.regional['pt-BR'],
{'showAnim':'fold','dateFormat':'dd/mm/yy'}
)
);
});
Or, you can use live method...
Just Import ext.jqrelcopy.JQRelcopy in your form file at the top
Yii::import('ext.jqrelcopy.JQRelcopy');
Your Problem be solved if any Issue let me know i will further assist.