开发者

transfer data from view to controller and back to view

been days im struggling with this. the problem is as follows...

I'm a newbie in the world of yii

So i have got a page 'resultat' and on selecting different menus, the content needs to be change through ajax.

Here the view:

 <!--Content_Resultat-->
<div class="content_resultat">
    <div class="header">
        <div class="header_top">
            <div class="centerheader"> 
            <a href="#">retournez à l'étape en cours</a>
            </div>
        </div>
        <div class="header_bottom">
        <ul class="centerlist">
            <li><a href="#"><span>1</span> votre piece</a></li>
            <li><a href="#"><span>2</span> votre exigence</a></li>
            <li><a href="#"><span>3</span> vos autre apareils</a></li>
         开发者_运维知识库   <li><a href="#"><span>4</span> votre utilisation</a></li>
        </ul>
    </div>
    </div>
    <div class="barre_titre">
        <a href="#">
            pour vous, lg vous propose
        </a>
        <div class="print">
            <a href="#">imprimer la liste</a>
        </div>
    </div>
    <div id="container">
    <?php echo CHtml::beginForm();?>
        <div class="onglet">
            <ul class="menu"> 
                 <?php $i = 1;
                    foreach ($data as $categorie) {?>
                    <li class="active">
                     <div class="onglet<?php echo $i;?>">
                        <img alt="no-picture" src="<?php echo $categorie->image;?>" />
                        <h4><?php echo CHtml::ajaxLink(
                        $categorie->titre,
                            Yii::app()->createUrl('getproduit'),
                            array('type'=>'POST',
                                'dataType' =>'json',
                                'enableAjaxValidation'=>true,
                                'update'=>'#carousel_container .contentWrapper #carousel_inner',
                                'data'=>'js:jQuery(".menu li h4 a").serialize()',
                                'success'=>'function(data){ $("#carousel_container li").text(data);}',

                                'error'=>'function(a,b,c){alert(b)}'
                  ));?></h4>
                     </div>
                    </li>   

                <?php $i++; }?>
            </ul>
        </div>
    </div>

    <div class="carousel_tv" id="carousel_container">

            <div class="contentWrapper">
                <div id="carousel_inner">
                    <ul id="carousel_ul">
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image1.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image2.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image3.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image1.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image2.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image3.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image1.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image2.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="carousel_pic">
                                <img alt="no-picture" src="images/image3.png" />
                                <div>
                                    <h3>gamme le5510</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <div>
                    <h1>No Content</h1>
                </div>
                <div>
                    <h1>No Content</h1>
                </div>
            </div>

        </div>
    </div>
<?php echo CHtml::endForm();?>

the data is being displayed through an xml.

the controller:

    public function actionGetproduit(){
    $obj_produit = new Gamme();
    $produits = $obj_produit->get_produits('tv');

    foreach ($produits as $data){

        echo CHtml::tag('produit',array('style'=>'display:block'),CHtml::encode($data),true);


    }   

}

I need the data being send from the controller to be displayed on the view..

But unable to do it, any help plss

Thanks :-(


For ajax returns, you generally would can use renderPartial or echo the results as you have it, but the CHtml::tag functions you would usually pass an HTML object for the tag name, see here or here but it looks like your function is expecting JSON, so you would need to output your results as JSON, see the Yii JSON methods. If that's not the issue, you might need to explain a bit more.


Normally with Yii on ajax button or link or what ever the case might be, you do a on success

array('success'=>'js:function(data) {
 jQuery("div#status").html(data);
}

and inside your controller, you can echo the response back to your view. Also make sure you have jQuery loaded in the view!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜