Problème avec CheckBoxList

Par Mushroom, il y a 12 ans


Bonjour tout le monde j'ai un pti problème (un gros à vrai dire.

J'essaye de mettre en place une CheckBoxList (je précise que j'utilise Yii framework et que je suis un total débutant dans le monde de la programmation web)le problème c'est que quand je coche la case et clique sur 'ajouter' ça ne m'arche pas l'objet n'est pas ajouté ça ne fait que rafraîchie la page.

J'ai beau lire la doc et chercher à droite à gauche sur le net je ne trouve pas de rép. Svp un pti coup de main serai vraiment de bonne augure merci.

View code

<td style="width:10%;">
            <?php 
                        echo CHtml::CheckboxList('PropUnit', 'property_id', array(' ', 

                            )
                            );
                    ?>
        </td>

le code du controller

public function actionqddunittobrochure
{ if(isset($_GET'property_id']))
        {
            $model->property_id=$_GET'property_id'];
            if($model->save())
                $this->redirect(array('create',
                                    'brochure_id'=>$model->brochure_id,
                                    'TitleName'=>$_GET'TitleName'],
                                    'PropUnitType'=>$_GET'PropUnitType'],
                                    'PropLocation'=>$_GET'PropLocation'],
                                    'ProjectType'=>$_GET'ProjectType'],
                                    'MaxFinishedYear'=>$_GET'MaxFinishedYear'],
                                    'MinFinishedYear'=>$_GET'MinFinishedYear'],
                                    'MinRent'=>$_GET'MinRent'],
                                    'MaxRent'=>$_GET'MaxRent'],
                                    'BMinRent'=>$_GET'BMinRent'],
                                    'BMaxRent'=>$_GET'BMaxRent'],
                                    'Pet'=>$_GET'Pet'],
                                    'Rented'=>$_GET'Rented'],
                                    ));
        }

                $propetryunit =new PropUnit();
        //$search_list = array('PropUnitType','PropLocation','FinishedYear','ProjectType','PriceRent','Title');

                $this->render('create',array(
            'model'=>$model,
                        'dataProvider'=>$dataProvider,
                        'brochure_id'=>$model->brochure_id,
                        'choosedataProvider'=>$chooseUnitDetail,//choosedataProvider,
                        //'sql'=>$propcondition,

                        //'Testdata'=>$choosedataProvider,
                        //'count'=>$count,

                        'property'=>$propetryunit, 
                        'modelUnit'=>$modelUnit,
                        'TitleName'=>$_GET'TitleName'],
                        'PropUnitType'=>$_GET'PropUnitType'],
                        'PropLocation'=>$_GET'PropLocation'],
                        'ProjectType'=>$_GET'ProjectType'],
                        'MaxFinishedYear'=>$_GET'MaxFinishedYear'],
                        'MinFinishedYear'=>$_GET'MinFinishedYear'],
                        'MinRent'=>$_GET'MinRent'],
                        'MaxRent'=>$_GET'MaxRent'],
                        'BMinRent'=>$_GET'BMinRent'],
                        'BMaxRent'=>$_GET'BMaxRent'],
                        'Pet'=>$_GET'Pet'],
                        'Rented'=>$_GET'Rented'],
        ));

    }}

17 réponses

SevDevSar, il y a 12 ans

ta oublier public function actionqddunittobrochure "($get_property_id)"{ et tu avais un "}" en trop, pour le reste je ces pas j'ai pas ton code entier

public function actionqddunittobrochure($get_property_id){
        if(isset($_GET'property_id']))
        {
            $model->property_id=$_GET'property_id'];
            if($model->save())
                $this->redirect(array('create',
                    'brochure_id'=>$model->brochure_id,
                    'TitleName'=>$_GET'TitleName'],
                    'PropUnitType'=>$_GET'PropUnitType'],
                    'PropLocation'=>$_GET'PropLocation'],
                    'ProjectType'=>$_GET'ProjectType'],
                    'MaxFinishedYear'=>$_GET'MaxFinishedYear'],
                    'MinFinishedYear'=>$_GET'MinFinishedYear'],
                    'MinRent'=>$_GET'MinRent'],
                    'MaxRent'=>$_GET'MaxRent'],
                    'BMinRent'=>$_GET'BMinRent'],
                    'BMaxRent'=>$_GET'BMaxRent'],
                    'Pet'=>$_GET'Pet'],
                    'Rented'=>$_GET'Rented'],
                ));
        }

        $propetryunit =new PropUnit();
        //$search_list = array('PropUnitType','PropLocation','FinishedYear','ProjectType','PriceRent','Title');

        $this->render('create',array(
            'model'=>$model,
            'dataProvider'=>$dataProvider,
            'brochure_id'=>$model->brochure_id,
            'choosedataProvider'=>$chooseUnitDetail,//choosedataProvider,
            //'sql'=>$propcondition,

            //'Testdata'=>$choosedataProvider,
            //'count'=>$count,

            'property'=>$propetryunit,
            'modelUnit'=>$modelUnit,
            'TitleName'=>$_GET'TitleName'],
            'PropUnitType'=>$_GET'PropUnitType'],
            'PropLocation'=>$_GET'PropLocation'],
            'ProjectType'=>$_GET'ProjectType'],
            'MaxFinishedYear'=>$_GET'MaxFinishedYear'],
            'MinFinishedYear'=>$_GET'MinFinishedYear'],
            'MinRent'=>$_GET'MinRent'],
            'MaxRent'=>$_GET'MaxRent'],
            'BMinRent'=>$_GET'BMinRent'],
            'BMaxRent'=>$_GET'BMaxRent'],
            'Pet'=>$_GET'Pet'],
            'Rented'=>$_GET'Rented'],
        ));
    }

et pour le utiliser ces sa

actionqddunittobrochure($_GET'property_id']);
Mushroom, il y a 12 ans

merci pour votre réponse
mais ça ne marche toujours pas

SevDevSar, il y a 12 ans

j'ai pas dit que le problème été régler :) je tes juste fait remarquer sur des erreur de structure de ton code, je connais pas toute la structure de ton code pour pouvoirs essayer de l’aidez et je de bien essayer

Mushroom, il y a 12 ans

si vous pouvez essayer de me donner un petit coup de main je serai vraiment très reconnaissant; je suis qu'un simple début et je galère vraiment sur ça

SevDevSar, il y a 12 ans

voila j'ai fait des modification et comment la utiliser mes il y y encore des petute chosse que je comprend pas, ou ce trouve ces variable? dans la meme class que ta fonction actionqddunittobrochure() ?

$model
$dataProvider
$chooseUnitDetail
$propetryunit
$modelUnit

public function actionqddunittobrochure($array = null){
        if(isset($array'property_id']))
        {
            $model->property_id = $array'property_id'];
            if($model->save())
                $this->redirect(array('create',
                    'brochure_id'=>$model->brochure_id,
                    'TitleName'=>$array'TitleName'],
                    'PropUnitType'=>$array'PropUnitType'],
                    'PropLocation'=>$array'PropLocation'],
                    'ProjectType'=>$array'ProjectType'],
                    'MaxFinishedYear'=>$array'MaxFinishedYear'],
                    'MinFinishedYear'=>$array'MinFinishedYear'],
                    'MinRent'=>$array'MinRent'],
                    'MaxRent'=>$array'MaxRent'],
                    'BMinRent'=>$array'BMinRent'],
                    'BMaxRent'=>$array'BMaxRent'],
                    'Pet'=>$array'Pet'],
                    'Rented'=>$array'Rented'],
                ));
        }
        $propetryunit =new PropUnit();
        //$search_list = array('PropUnitType','PropLocation','FinishedYear','ProjectType','PriceRent','Title');
        $this->render('create',array(
            'model'=>$model,
            'dataProvider' => $dataProvider,
            'brochure_id' => $model->brochure_id,
            'choosedataProvider' => $chooseUnitDetail,//choosedataProvider,
            //'sql'=>$propcondition,
            //'Testdata'=>$choosedataProvider,
            //'count'=>$count,
            'property'=>$propetryunit,
            'modelUnit'=>$modelUnit,
            'TitleName'=>$array'TitleName'],
            'PropUnitType'=>$array'PropUnitType'],
            'PropLocation'=>$array'PropLocation'],
            'ProjectType'=>$array'ProjectType'],
            'MaxFinishedYear'=>$array'MaxFinishedYear'],
            'MinFinishedYear'=>$array'MinFinishedYear'],
            'MinRent'=>$array'MinRent'],
            'MaxRent'=>$array'MaxRent'],
            'BMinRent'=>$array'BMinRent'],
            'BMaxRent'=>$array'BMaxRent'],
            'Pet'=>$array'Pet'],
            'Rented'=>$array'Rented'],
        ));
    }

et pour le utiliser

$array = array(
        'property_id' => $_GET'property_id'],
        'TitleName'=>$_GET'TitleName'],
        'PropUnitType'=>$_GET'PropUnitType'],
        'PropLocation'=>$_GET'PropLocation'],
        'ProjectType'=>$_GET'ProjectType'],
        'MaxFinishedYear'=>$_GET'MaxFinishedYear'],
        'MinFinishedYear'=>$_GET'MinFinishedYear'],
        'MinRent'=>$_GET'MinRent'],
        'MaxRent'=>$_GET'MaxRent'],
        'BMinRent'=>$_GET'BMinRent'],
        'BMaxRent'=>$_GET'BMaxRent'],
        'Pet'=>$_GET'Pet'],
        'Rented'=>$_GET'Rented'],
    );
    actionqddunittobrochure($array);
SevDevSar, il y a 12 ans

et encore une chose tu a instancier $propetryunit = new PropUnit(); et puis tu a utiliser 'property' => $propetryunit et la ta aussi une erreur tu dois pointer sur la fonction qui se trouve dans PropUnit(), exemple $propetryunit->le nom de la fonction, et je ces pas si les variable ou fonction $modelUnit et $chooseUnitDetail fons partie de PropUnit()?

et les autre variable $model, $dataProvider, $chooseUnitDetail, $modelUnit si elle se trouve dans la même class se qui devrais être ce cat, tu dois les appeler de cette façon : $this->model, $this->dataProvider et ces fonction doive être en public, private

Mushroom, il y a 12 ans

ça me déclare l'erreur suivante

Undefined index: property_id

et pour les variable en questions oui dans la même classe

SevDevSar, il y a 12 ans

$model->property_id la variable $model vien de ou? tu a instancier une class? $model se trouve a l'exterieur de ta fonction actionqddunittobrochure() tu dois aussi faire $this->model->property_id et maitre $model en public

si non tu la instancie dans ta clas et tu fait comme ta fait $model->property_id et ne oublie pas de maitre () a chaque class comme $model->property_id()

Mushroom, il y a 12 ans

oui c'est ce que j'ai fais

public function actionaddunittobrochure($array = null){

        if(isset($array'property_id']))
        {$this->model->property_id;

mais toujours la même erreur
je m'excuse si je vous dérange avec ça, je me lance à peine et je ne métrise pas bcp pardonnez moi

SevDevSar, il y a 12 ans

si tu envoyer tout le code de ta class avec ta fonction actionaddunittobrochure() et le code de ta class PropUnit()

SevDevSar, il y a 12 ans

déjà ta une erreur ces que $model et instancier dans une autre fonction actionCreate() et pas dans ta class en public, j'ai fait la modification dans ta fonction actionaddunittobrochure() et ne oublie pas modifier tout ce qui vas avec la variable $propetryunit et tu dois appeler une fonction dans $this->render pour $model, et supprime le dernier message que ta envoyer avec tout le code de ta class et la view sa prend trop de place dans forum :)

public function actionaddunittobrochure($array = null){

        $model = new Haves;

        if(isset($array'property_id']))
        {
            $model->property_id = $array'property_id'];
            if($model->save())
                $this->redirect(array('create',
                    'brochure_id'=>$model->brochure_id,
                    'TitleName'=>$array'TitleName'],
                    'PropUnitType'=>$array'PropUnitType'],
                    'PropLocation'=>$array'PropLocation'],
                    'ProjectType'=>$array'ProjectType'],
                    'MaxFinishedYear'=>$array'MaxFinishedYear'],
                    'MinFinishedYear'=>$array'MinFinishedYear'],
                    'MinRent'=>$array'MinRent'],
                    'MaxRent'=>$array'MaxRent'],
                    'BMinRent'=>$array'BMinRent'],
                    'BMaxRent'=>$array'BMaxRent'],
                    'Pet'=>$array'Pet'],
                    'Rented'=>$array'Rented'],
                ));
        }

        $propetryunit =new PropUnit();
        //$search_list = array('PropUnitType','PropLocation','FinishedYear','ProjectType','PriceRent','Title');

        $this->render('create',array(
            'model'=>$model, // et ici tu dois appeler une fonction?
            'dataProvider' => $dataProvider,
            'brochure_id' => $model->brochure_id,
            'choosedataProvider' => $chooseUnitDetail,//choosedataProvider,
            //'sql'=>$propcondition,

            //'Testdata'=>$choosedataProvider,
            //'count'=>$count,

            'property'=>$propetryunit,
            'modelUnit'=>$modelUnit,
            'TitleName'=>$array'TitleName'],
            'PropUnitType'=>$array'PropUnitType'],
            'PropLocation'=>$array'PropLocation'],
            'ProjectType'=>$array'ProjectType'],
            'MaxFinishedYear'=>$array'MaxFinishedYear'],
            'MinFinishedYear'=>$array'MinFinishedYear'],
            'MinRent'=>$array'MinRent'],
            'MaxRent'=>$array'MaxRent'],
            'BMinRent'=>$array'BMinRent'],
            'BMaxRent'=>$array'BMaxRent'],
            'Pet'=>$array'Pet'],
            'Rented'=>$array'Rented'],
        ));
    }
SevDevSar, il y a 12 ans

et ta aussi une erreur dans ta fonction, $id sa devrais être $brochure_id si je me trompe pas

public function actionView($brochure_id)
    {
        $this->render('view',array(
            'model'=>$this->loadModel($id),
        ));
    }

voila je suis in-peux fatiguer avec ce code la tu devrais pouvoir te retrouvez et trouvez ta solution a ton problème, juste une petit chose pour utiliser ta fonction il y a une faute de orthographe je ces pas si tu la remarquer actionqddunittobrochure() ces actionaddunittobrochure()

Mushroom, il y a 12 ans

quelle fonction au juste je doit appeler dans $this->render ? et je n'ai pas bien compris les modifs que je soit faire sur $propetryunit

SevDevSar, il y a 12 ans

$propetryunit = new PropUnit(); ta fait appel a une intention de la classe PropUnit(), pour la utiliser tu dois faire $propetryunit->la fonction que tu veux utiliser, si non pour quoi avoir fait une intention de PropUnit(), et dans $this->render tu a 'model'=>$model, mes ta pas fait appel a une fonction pour $model->la fonction que tu veux utiliser.

tu a tout ce que il te faut et ces a toi de faire le reste qui a faire

Mushroom, il y a 12 ans

ok merci infiniment pour votre aide je vais essayer de me débrouiller avec vos précieuses infos.
encore une fois désolé de vous avoir dérangé avec tout ça.
bonne soirée

SevDevSar, il y a 12 ans

j'ai juste un conseil a te donnez ces de apprendre le fonctionnement de la programmation orienter objet avant de continuer avec tes script, comme tu comprend pas la programation orienter objet tu vas toujours avoir des problème de ce genre.

Mushroom, il y a 12 ans

merci pour votre conseil, oui c'est ce que je suis entrain de faire en parallèle avec ça