請求書を作成するフォームがあります。送信者と受信者のフォーム入力は、データベース内の使用可能なリストから取得されます。
accounts(id,...., company_name, abn) ---> id is primary
users(id, username, title, firstname, surname,...) ---> id is primary
accounts_users(id, account_id, user_id) --->account_id from accounts, user_id from users
各ユーザーは 1 つのアカウントにのみ属することができますが、1 つのアカウントには複数のユーザーを含めることができます。フォーム入力は、ログインしているユーザーに応じた account_id です。
請求書コントローラーで:
$accounts3=$this->User->AccountsUser->find('list', array(
'fields'=>array('account_id','account_id'),'conditions' => array(
'user_id' => $this->Auth->user('id'))));
$accounts=$this->User->Relationship->find('list', array('fields'=>array('receiver_id'),'conditions' => array('sender_id' => $accounts2)));
addInvoice ビューで:
<?php
echo $this->Form->create('Invoice', array('action'=>'addinvoice'));
echo $this->Form->input('sender_id',array('label'=>'Sender: ', 'options' => array('$accounts3' => 'COMPANY NAME')));
echo $this->Form->input('receiver_id',array('label'=>'Receiver: ', 'type' => 'select', 'options' => $accounts));
echo $this->Form->input('active', array('label' => 'Schedule?', 'options' => array('1'=>'Send','0'=>'Schedule'), 'default'=>'1'));
echo $this->Form->hidden('templates_id', array('default'=>'0'));
echo $this->Form->end('Submit');
この場合の「COMPANY NAME」のラベルはハードコードされており、テーブルcompany_name
からの動的なラベルに置き換える必要がありaccounts
ます。
もう少し複雑なことに、レシーバー ラベルは からのものでcompany_name
あるaccounts
必要company_name
がありNULL
ます。username
users
試行された解決策: ***$sendername
変数を作成中InvoicesController
$sendername=$this->User->Account->find('list', array('fields'=>array('company_name'),'conditions' => array('account_id' => $accounts3)));
また
$sendername=$this->User->AccountsUser->find('list', array('fields'=>array('id','company_name'),'conditions' => array('user_id' => $this->Auth->user('id'))));
それらは機能していないようですが、CakePHP でも可能でしょうか?