저는 Yii를 처음 사용하며 음식 쇼핑을 관리하는 취미 웹 사이트를 만들어 이해하려고합니다. 내 조리법을 나열하고 +/- 버튼을 눌러 각 레시피 옆에 동일한 페이지의 쇼핑 목록을 업데이트하는 페이지를 만들려고합니다. 모든 요리 재료와 쇼핑 목록은 SQL 데이터베이스에 저장됩니다.모델 및 데이터 지원을 이해하는 데 도움이 필요합니다.
지금까지 ShoppingListController라는 컨트롤러가 있고 actionIndex() 함수 (조리법과 쇼핑 목록을 보여줍니다)에서 두 개의 dataprovider 및 모델 (폼의 +/- 버튼의 경우)을 만들고 있습니다. 내보기에 전달 다음과 같이
// Create a shopping list item model
$shoppingListModel = new TblShoppingListItem;
// Get the saved shopping list data from the shopping list table
$shoppingDataProvider = new CActiveDataProvider('TblShoppingListItem', array(
'criteria'=>array(
'select'=>array('recipe_id', 'recipe_multiplier')),
'pagination'=>array('pageSize'=>500)
));
// Get the recipe ingredient data from the recipe models and order by recipe name
$recipeDataProvider = new CActiveDataProvider('TblRecipeIngredient', array(
'criteria'=>array(
'select'=>array('recipe_id', 'ingredient_id', 'ingredient_unit_id', 'ingredient_amount'),
'with'=>array('recipe','ingredient','ingredientUnit'),
'together'=>true,
'order'=>'recipe.name ASC'),
'pagination'=>array('pageSize'=>500)
));
// Render the 'shoppinglist/show' page
$this->render('show', array(
'recipeDataProvider'=>$recipeDataProvider,
'shoppingDataProvider'=>$shoppingDataProvider,
'shoppingListModel'=>$shoppingListModel
));
나는 조금 혼란 스러워요 - 내가, 내가 그래서 내 쇼핑 목록을 표시 할 수 있습니다 첫 번째 데이터 공급자를 필요로하는 +/- 형태로 전달하는 모델을 필요로하는 것 내 레서피 정보를 표시 할 수 있도록 두 번째 데이터 공급자가 필요합니다.
그러나 실제로 shoppingListModel과 shoppingDataProvider (즉, 나쁜 습관을 모두 갖고있는 것)가 필요한지 궁금합니다. 모델에서 필요한 정보를 얻을 수 있을까요?. 모델과 데이터 제공 업체의 차이점에 대해 혼란 스럽습니다.
오래된 쇼핑 목록을 표시하고 있습니까? 아니면 현재의 것일까요? 저장된 쇼핑 목록 데이터의 의미는 무엇입니까? recipe_multiplier의 중요성을 말해 줄 수 있습니까? 그리고 쇼핑 목록은 제조법과 정확히 어떻게 관련이 있습니까? 논리적으로 말하면, 관계를 어떻게 설명합니까? –
이 질문은 대답하기에는 너무 광범위하고 모호합니다. Mewzer가 Yii의 ActiveRecord 관계에 대해 읽는 시간을 보내고 싶다고 추천합니다. http://www.yiiframework.com/doc/guide/1.1/en/database.arr – thaddeusmt