JQuery how to... start

Hi everyone one,

I’m quite new to web programming, I found my way with Yii and PHP, but I’m really blank on how to use JQuery withing Yii. I tried to find some sort of “how to use JQuery”, a dumb simple example, to put me on track, but I didn’t find anything. My apologize if I missed it.

I found that register my script with something like :


Yii::app()->clientScript->registerScript("id","script",position);

I tried to put a simple slider in my page with this code :


<?php

$script = "	<style type=\"text/css\">

		#demo-frame > div.demo { padding: 10px !important; };

	</style>

	<script type=\"text/javascript\">

	$(function() {

		$(\"#slider\").slider();

	});

	</script>";


Yii::app()->clientScript->registerScript("id",$script,CClientScript::POS_READY);


?>

<div class="demo">


<div id="slider"></div>


</div><!-- End demo -->



But it doesn’t work, I guess I would need to load the JQuery, or is Yii doing it for me ?

I feel a bit stupid asking such a basic question… sorry for that…

Use the following line to register jquery.


<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>




$cs=Yii::app()->getClientScript();

$cs->registerCoreScript('jquery');

$cs->registerScriptFile('/myapp/js/myscript.js');



registerCss for the CSS part,

registerScript for the javascript (without script tags)

/Tommy

This might be more understandable.

The first line of the javascript will execute the slider when the page is loaded.


<html>

<head>

<style type="text/css">

    #demo-frame > div.demo { padding: 10px !important; };

</style>


<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>


<script type="text/javascript">

    $(document).ready(function(){

        $("#slider").slider();

    });

</script>

</head>

<body>

<div class="demo">

    <div id="slider"></div>

</div>

</body>

</html>

Thank you so much for all the great inputs, its really helpful, thank you !

However, I didn’t get it to work yet… my page is displayed, but the slider doesn’t show.

My guess is that I am not loading all the js files that I need like ui.slider.js, but the funny thing is, I can’t find that file in the JQuery installed by Yii. I find some of the UI scripts, such as tab and treeview, but the one I really need is accordion and it’s not there.

Of course I could take it from the JQuery standalone distribution. But isn’t Yii implementing the whole JQuery package ? I don’t want to add scripts if they are already installed somewhere.

Any idea ? Even searching through the files in both my app directory and the framework directory I don’t find anything.

So… I guess I should install a full copy of JQuery on the side…

checkout version 1.1 for the jq ui widgets in the zii library (zii.googlecode.com)

I didn’t think about that one, thanks :slight_smile: