私はCakeとMVCの一般的な話に新しくなりました。私は行かなくても良い習慣を確立したい。良い習慣の中にはコントローラをリーンにして、モデルを太くすることがあります。しかし、それは私のようなnoobのための動きのターゲットのビットです。あるモデルから別のモデルに情報を渡す必要がある場合は、すべてをコントローラにダンプするだけですか?それをモデルで動作させるようにしてください。CakePHPでスキニーコントローラと脂肪モデルを作成しようとするガイダンス
ここには、私が整理しようとしている混乱の一種の例があります。
すべてはコントローラ内にあるようなと思われますが、間違っている可能性があります。このアクションはメンバのリストを取得し、それをビューに送信します。ビューでは、アカウントを「有効にする」メンバーをチェックすることができます。 ACLなし、単純な認証。私は、 "サブ管理者"はdbフィールド、client_idを使用して管理できるユーザーのみを確認するようにしています。私が使用している2つのモデルはUserとClientです。私の目には
public function activate() {
if ($this->request->is('get')) {
$id = $this->Auth->user('id');
$this->User->id = $id; //make sure current User is the logged in user
$currentClient = $this->User->field('client_id'); // get client_id based on logged in user
$members = $this->User->Client->find('first', array(// find users that have the same client_id
'conditions' => array('id' => $currentClient),
'recursive' => 1
));
$this->set('clients', $members); // send the users to the view
} else if ($this->request->is('post') || $this->request->is('put')) {
$members = $this->request->data['Members']; // grab players submitted from push form
$memberIds = array(); // this will hold the selected users
foreach($members as $a){
$memberIds[$a['id']] = $a['id']; // loop over user's that were selected
}
$usersToActivate = $this->User->find('all', array(//find user records, based on the array of id's
'conditions' => array(
"User.id" => $memberIds
)
));
$this->Ticket->bulkActivate($usersToActivate); // send array of members into model for processing
$this->Session->setFlash('Activations sent.', 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
}
}
は、それが大幅に間違って見ていない...と私はすでにモデルにいくつかの処理をやっている(実際にユーザレコードを取るbulkActivateで見られるように、活性化チケットを生成します) 。
しかし、まだ100%ではないと感じることはできません。
そこには冗談がありました。あなたはそれを見つけました! –