0

私の問題は次のとおりです。

ログイン ビューの代わりにログイン要素を使用したいと考えています。そのため、default.ctp でログインを使用できます... ユーザーがすべてのページからログインできるようにしたいと考えています。これは一種のドロップダウン メニューである必要があります。

コントローラーに要素を使用して、ビューではなく要素データを取得するように指示するにはどうすればよいですか?

私の LoginsController ログイン機能:

function login()
{
    $this->set('headline','Melden Sie sich an...');

    if($this->request->is('post'))
    {
        if($this->Auth->login())
        {
            //$this->redirect($this->Auth->redirect);
            $this->redirect(array('action' => 'index'));
            $this->Session->setFlash('Ihr Login war erfolgreich!');
        }
        else
        {
          //  $this->Session->setFlash('Ihre Email/Passwort ist falsch!' . ' ' . $this->request->data['Login']['email'] . ' ' . $this->request->data['Login']['password']);
            $this->Session->setFlash('Ihre Email/Passwort ist falsch!');
        }
    }
    $this->render('logins/login');
}

私のビュー/要素:

<aside id="left">

<div class="whitebox einloggen">
    <div class="rahmen">
        <h2>Login</h2>
        <div class="inside">

  <?php              echo $this->Html->para(null,'Sind Sie bereits als Nutzer registriert?');



    echo $this->Form->create('Login', array('action' => 'login'));

    echo $this->Form->input('email', array ('label' => false, 'type'=>'text','class'=>'text', 'value'=>'E-Mail','id'=>'LoginEmail', 'onfocus'=>"resetinput(this);", 'onBlur'=>"fillinput(this);"));
    echo $this->Form->input('password', array ('label' => false, 'type'=>'text','class'=>'text', 'value'=>'Passwort','id'=>'LoginPassword', 'onfocus'=>"resetinputpw(this);", 'onBlur'=>"fillinput(this);"));
    echo $this->Form->end(array('label'=>'Einloggen','class' => 'button long','type' => 'submit','name'=>'submit'));

    echo $this->Html->para('forgetpw', $this->Html->link('Passwort vergessen?', array('controller' => 'login', 'action' => 'forgotpwd'), array('label' => false, 'class' => 'forgetpw', 'title'=>'Passwort vergessen')));

    echo $this->Html->link('', array('controller' => 'login', 'action' => 'fblogin'), array('class' => 'facebook-button', 'title'=>'Mit Facebook einloggen'));
    ?>

        </div>
    </div>
</div>

次のように default.ctp の要素を呼び出します。

<?php    echo $this->element('/logins/login'); ?>

ログインビューがないことについて常に不平を言っています...

これが良い習慣でない場合は、別の方法を教えてください;-)

私の悪い英語でごめんなさい、そしてありがとう!

4

1 に答える 1

0

コントローラーでビューを無効にしてみましたか?

要素が default.ctp に含まれている場合、追加

$this->autoRender = false;

代わりに

$this->render('logins/login');

ログインコントローラーで、ログインコントローラーがビューを明確にレンダリングしようとするのを停止します。

要素を Elements ディレクトリ ('Views' の下) に配置し、default.ctp のコードを次のように更新する必要があります。

<?php echo $this->element('login'); ?>

また、リンクとフォームを設定する Cakephp の方法を使用すると、要素で役立つ場合があります。

フォームの完全なガイダンスについては、こちらを試してください: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

簡単な方法でリンクを作成する方法については、http: //book.cakephp.org/2.0/en/core-libraries/helpers/html.htmlを試してください。

于 2012-11-25T20:11:38.280 に答える