2016-11-13 139 views
0

我有一個意外的文件錯誤結束,但我檢查了我的代碼,我沒有發現這個錯誤的任何跡象!那麼你能告訴我可能是什麼原因造成這個問題!下面是包含錯誤(這是使用CakePHP做了一個項目)我的文件的代碼:文件意外結束

<?php 
    App::uses('AppController', 'Controller'); 

    class AdminsController extends AppController { 

    public function login($id = null) 
{  


    $this->layout='login'; 


    if ($this->request->is('post')) { 

     $user=$this->request->data['Admin']['r']; 



     if ($user == 'Administrator') 
     { 
      $Admin=$this->request->data['Admin']['login']; 
      $mdp=$this->request->data['Admin']['motpasse']; 

      $Admins=$this->Admin->find('count',array('conditions'=>array('Admin.login'=>$Admin,'Admin.motpasse'=>$mdp))); 

      if ($Admins ==1) 
       {sleep(2); 
        CakeSession::write('admin','admin'); 
        CakeSession::write('nom',$Admin); 
        $this->redirect(array('action' => 'index')); 

       }else {?><script type="text/javascript"> 
       confirm('M.Admin Login ou Mot de passe incorrect'); 
      </script><?} 

     } 


     if ($user == 'Commercial') 
     { 
      App::Import('Model', 'Commercial'); 

      $Admin=$this->request->data['Admin']['login']; 
      $mdp=$this->request->data['Admin']['motpasse']; 

      $category = new Commercial(); 
      $categories = $category->find('count',array('conditions'=>array('Commercial.login'=>$Admin,'Commercial.motpasse'=>$mdp))); 

      if ($categories ==1) 
      { 
       CakeSession::write('admin','com'); 
       CakeSession::write('nom',$Admin); 
       $this->redirect(array('controller' => 'Commercials', 'action' => '')); 
      } 

     } 
    } 
} 



public function logout($id = null) 
{  
    $this->Session->destroy(); 
    $this->redirect(array('action' => 'login')); 




} 


    public function index() { 

$admin=CakeSession::read('admin'); 
if(($admin<>'admin')&&($admin<>'com')) 
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));} 

if($admin=='com') 
    {$this->layout='Commercials';} 

$this->Admin->recursive = 0; 
$this->set('admins', $this->paginate()); 
    } 


    public function view($id = null) { 

$admin=CakeSession::read('admin'); 
if(($admin<>'admin')&&($admin<>'com')) 
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));} 

if($admin=='com') 
    {$this->layout='Commercials';} 

if (!$this->Admin->exists($id)) { 
    throw new NotFoundException(__('Invalid admin')); 
} 
$options = array('conditions' => array('Admin.' . $this->Admin->primaryKey => $id)); 
$this->set('admin', $this->Admin->find('first', $options)); 
    } 


    public function add() { 

$admin=CakeSession::read('admin'); 
if(($admin<>'admin')&&($admin<>'com')) 
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));} 

if($admin=='com') 
    {$this->layout='Commercials';} 

if ($this->request->is('post')) { 
    $this->Admin->create(); 
    if ($this->Admin->save($this->request->data)) { 
     $this->Session->setFlash(__('The admin has been saved')); 
     $this->redirect(array('action' => 'index')); 
    } else { 
     $this->Session->setFlash(__('The admin could not be saved. Please, try again.')); 
    } 
} 
$questionnaires = $this->Admin->Questionnaire->find('list'); 
$this->set(compact('questionnaires')); 
    } 


    public function delete($id = null) { 

$admin=CakeSession::read('admin'); 
if(($admin<>'admin')&&($admin<>'com')) 
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));} 

if($admin=='com') 
    {$this->layout='Commercials';} 

$this->Admin->id = $id; 
if (!$this->Admin->exists()) { 
    throw new NotFoundException(__('Invalid admin')); 
} 
$this->request->onlyAllow('post', 'delete'); 
if ($this->Admin->delete()) { 
    $this->Session->setFlash(__('Admin deleted')); 
    $this->redirect(array('action' => 'index')); 
} 
$this->Session->setFlash(__('Admin was not deleted')); 
$this->redirect(array('action' => 'index')); 
    } 
    } 
    ?> 

這是顯示了錯誤:

enter image description here

+1

如果您修復了縮進,您可能會弄清楚什麼是未關閉的。 – chris85

+0

我在一個在線phpchecker上覆制了我的代碼,發現0個問題,所以我認爲這是一個錯誤的錯誤! –

回答

0

這裏看看:

if ($Admins ==1) 
      {sleep(2); 
       CakeSession::write('admin','admin'); 
       CakeSession::write('nom',$Admin); 
       $this->redirect(array('action' => 'index')); 

      }else {?><script type="text/javascript"> 
      confirm('M.Admin Login ou Mot de passe incorrect'); 
     </script><? } // look at here 
     ?> 

應該是:

if ($Admins ==1) 
      {sleep(2); 
       CakeSession::write('admin','admin'); 
       CakeSession::write('nom',$Admin); 
       $this->redirect(array('action' => 'index')); 

      }else {?><script type="text/javascript"> 
      confirm('M.Admin Login ou Mot de passe incorrect'); 
     </script><?php } // your little mistake was here 
     ?> 

您是否注意到您錯過了PHP。

+0

我添加了缺少的PHP,並且出現了另一個錯誤!很多他們,所以我問我是否可以發佈我的洞項目,所以你可以找出什麼是所有這些錯誤? –