Passing ID From URL

Hi everyone,

I’m new to YII :) and I am trying to replicate the application I made from scratch(Using PHP ofcourse) to YII. here’s the sample data model:

STORE


PK id

field1…

field2…

MENU CATEGORY


PK id

field1…

field2…

FK store_id

Now here’s the question. In the admin section I want to select a store and after that when I go to the menu_category page, I just want to see all the related menu category of that store. and when i go back to the store admin page. If I choose another store and go back to the menu category page. It will also display the new related store. I’m doing it with sessions in my past application. can someone help me :)

P.S. I just started using YII this week and studying about classes and framework and stuff. Thanks :) sorry for my english.

Explain better or draw, please.

Sorry for the wrong title XD. I have two tables "store" and "menucategory". I want to see all related menu category of a store that i click in the view or admin page so that i can have a filtered view on the menu category page.

This is the things i want to achieve.

  1. Pick a store in the store list.

  2. Redirect to the menu category admin or view page.

  3. Store the store_id in a variable to filter all the related menucategory list. (can only see the related menucategory of the store i picked)

  4. Pass that variable to other pages ex.(menu_group page, menu_item page). so all pages are filtered and related to the store.

Thanks for the response :)

I’m sure there are many ways to do this…

  1. When you pick a store in the list you can either have an ajax call or form submit button call an action on a Controller, /controller/action/store_id

  2. The Controller will ‘control’ the next step. It will take the store_id as a parameter to its function. Load the menu_category model based on the passed in store_id.

  3. You can put the store_id in a session variable by doing


Yii::app()->user->setState('store_id', $store_id);

  1. On other pages you can get the store_id from the session by

Yii::app()->user->getState('store_id');

Example, non-tested:




// inside a Controller

...


    public function actionPickStore()

    {

        if(isset($_POST['store_id'])) {

            $store_id=(int)$_POST['store_id'];

            $model = MenuCategoryModel::find('store_id = :store_id', array('store_id'=>$store_id)); // finds menu model by store_id

            Yii::app()->user->setState('store_id', $store_id); // save $store_id in session

            $this->render('view', array('model'=>$model)); // load a 'view' with your model

        }

    }



thanks cnick79 that’s what I want to achieve hehe :D gonna use your logic now:) Thanks!