0

ユーザーの請求書を吐き出すページを作成しようとしています。特定のユーザーの請求書の取得に問題があります。問題は、コントローラーの関数と$idの設定にあります。現在のユーザーに設定する方法がわかりません。

これが私の関数の関連コードです

public function payInvoice(){

    $this->set('title_for_layout', 'Pay Invoice');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.jpg');   
    $this->layout='home_layout';
    $userid = $this->Auth->user('id');
    $this->set('Invoices', $this->Invoice->findByBiller($userid));
}

これは私の見解を含む答えです:

<table width="100%" border="1">
                <tr>
                    <th>Biller</th>
                    <th>Subject</th>
                    <th>Date</th>
                    <th>Action</th>
                </tr>

                <?php foreach($Invoices as $invoice):?>
                    <tr> 
                        <td align='center'><?php echo $this->Html->link($Invoices['Invoice']['to'], 
                        array('action' => 'viewInvoice', $Invoices['Invoice']['to'])); ;?> </td>
                        <td align='center'><?php echo $Invoices['Invoice']['subject']; ?></td>
                        <td align='center'><?php echo $Invoices['Invoice']['datecreated']; ?></td>
                        <td align='center'><a href="viewinvoice"><button>View Invoice</button></a><a href="disputeinvoice"><button>Dispute Invoice</button></a></td>
                    </tr>
                <?php endforeach; ?>

            </table>

コードでは、ユーザー15がすべての請求書を表示できるようにハードコーディングしていますが、システムをハードコーディングしたくありません。に設定したいのです$id='currentuser'が、コーディング方法がわかりません。

ユーザーログイン機能

 public function login() {


    $this->set('title_for_layout', 'Individual Registration');
    $this->set('stylesheet_used', 'style');
    $this->set('image_used', 'eBOXLogo.jpg');

    if ($this->request->is('post')){
    $this->request->data['User']['password'] = 'qazwsx';
   if ($this->Auth->login()) {

       $this->redirect($this->Auth->redirect('eboxs/home'));
       $this->Session->write('Myid',$myid);
    } 
    else {
        $this->Session->setFlash('Username or password is incorrect');
    }
    }else{
    $this->Session->setFlash('Welcome, please login');
    }


}

どんな助けでも大歓迎です

4

3 に答える 3

0

現在のユーザーの場合、セッションが必要です。セッションにuser_idが含まれていると仮定します。これを試して

public function payInvoice(){
        $id=$this->Session->read('user_id');
        $this->set('title_for_layout', 'Pay Invoice');
        $this->set('stylesheet_used', 'homestyle');
        $this->set('image_used', 'eBOXLogoHome.jpg');   
        $this->layout='home_layout';
        $this->set('Invoices', $this->Invoice->findByBiller($id));
}
于 2012-05-24T05:02:36.177 に答える
0

値がuser_idであるセッションIDを割り当ててみませんか?

于 2012-05-24T04:10:44.327 に答える
0

ユーザーがその時間に正常にログインすると、次のようにセッションでIDを設定します。

   $this->Session->write('Myid',$myid);

$myidユーザー名とパスワードが正しい場合にデータベースからフェッチされます

コントローラーのどこにでもフェッチできます。

   $id = $this->Session->read('Myid');

そしてuはapp_controllerファイルに追加する必要はありません

于 2012-05-24T05:11:11.127 に答える