私はYiiの新人です。私の食料品の買い物を管理するための趣味のウェブサイトを作成して理解しようとしています。私は自分のレシピを一覧表示するページを作成しようとしており、各レシピの隣に+/-ボタンがあり、これを押すと同じページのショッピングリストが更新されます。レシピ成分と買い物リストはすべてSQLデータベースに保存されています。ヘルプモデルとデータ提供者が必要です
これまでのところ、私はShoppingListControllerというコントローラを持っていましたが、私のactionIndex()関数(レシピと買い物リストを表示しています)では、2つの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
));
私は少し混乱しています - 私は、私は、私は、私の買い物リストを表示することができます最初のデータプロバイダを必要とする+/-フォームに渡すモデルを必要とするように見えますレシピ情報を表示できるように、2番目のデータプロバイダが必要です。
しかし、私は実際にshoppingListModelとshoppingDataProvider(つまり両方の悪い習慣を持っています)が必要なのでしょうか?私はモデルからちょうど必要な情報を得ることができますか?私は、モデルとデータプロバイダの違いによって混乱しています。
古いショッピングリストを表示していますか?それとも現在のものだけ?そして、保存された買い物リストのデータはどういう意味ですか? recipe_multiplierの重要性は何ですか?そして買い物リストはレシピと正確にどのように関係していますか、論理的には、関係をどう説明しますか? –
この質問はあまりにも広すぎ、答えが曖昧です。私はMewzerがYiiのActiveRecord関係について読んだことをお伝えすることをお勧めします。それは物事を明確にするのに役立ちます:http://www.yiiframework.com/doc/guide/1.1/en/database.arr – thaddeusmt