2010-07-22 4 views
6

필자는 PHP에서 아주 기본적인 LDAP/AD 기능을 위해 작성한 독립형 클래스를 사용하고 있습니다. 나는 cakephp에서 작업하고있는 프로젝트에서이 클래스를 사용하고 싶습니다. CakePHP는 1.2 난 그냥 공급 업체로 클래스를 추가 할 수 있습니다 같은cakephp 1.3에서 독립 실행 형 클래스를 사용하려면 어떻게해야합니까?

그것은 그러나 그것은 공급 업체 CakePHP는 1.3 제거 지원처럼 보이는 보인다. 그러면이 클래스에서 몇 가지 함수를 호출하는 방법은 무엇입니까?

감사합니다 (I 클래스 자체를 동일하게 유지하고 불필요한 보인다, 플러그인으로 바꿀 수 없습니다하려고하고 싶습니다)! 아래

코드 :

**<?php 
class UsersController extends AppController { 

var $name = 'Users'; 

    //commented out because it breaks the script 
    //App::import('Lib', 'ldap'); 


function index() { 
    $this->User->recursive = 0; 
    $this->set('users', $this->paginate()); 
} 

    function login() { 

     if (!empty($this->data)) { 
       if ($ldap->auth($this->data['User']['user'],$this->data['User']['password'])) { 
         $this->Session->setFlash(__('The user has been saved', true)); 
         $this->Session->write('user', $this->data['User']['user']); 
         $this->redirect(array('action' => 'index')); 
       } else { 
         $this->Session->setFlash(__('Login Failed', true)); 
       } 
     } 
    } 

    function logout() { 
     $this->Session->delete('user'); 
     $this->redirect($this->referer()); 

    } 

function view($id = null) { 
    if (!$id) { 
     $this->Session->setFlash(__('Invalid user', true)); 
     $this->redirect(array('action' => 'index')); 
    } 
    $this->set('user', $this->User->read(null, $id)); 
} 

function add() { 
    if (!empty($this->data)) { 
     $this->User->create(); 
     if ($this->User->save($this->data)) { 
      $this->Session->setFlash(__('The user has been saved', true)); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); 
     } 
    } 
    $projects = $this->User->Project->find('list'); 
    $this->set(compact('projects')); 
} 

function edit($id = null) { 
    if (!$id && empty($this->data)) { 
     $this->Session->setFlash(__('Invalid user', true)); 
     $this->redirect(array('action' => 'index')); 
    } 
    if (!empty($this->data)) { 
     if ($this->User->save($this->data)) { 
      $this->Session->setFlash(__('The user has been saved', true)); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); 
     } 
    } 
    if (empty($this->data)) { 
     $this->data = $this->User->read(null, $id); 
    } 
    $projects = $this->User->Project->find('list'); 
    $this->set(compact('projects')); 
} 

function delete($id = null) { 
    if (!$id) { 
     $this->Session->setFlash(__('Invalid id for user', true)); 
     $this->redirect(array('action'=>'index')); 
    } 
    if ($this->User->delete($id)) { 
     $this->Session->setFlash(__('User deleted', true)); 
     $this->redirect(array('action'=>'index')); 
    } 
    $this->Session->setFlash(__('User was not deleted', true)); 
    $this->redirect(array('action' => 'index')); 
} 
} 
?>** 

답변

7

케이크 1.3은 아직 완벽 공급 업체 파일의 아이디어를 지원합니다. 또한 now also support "libraries", 타사 클래스가 아닌 추가 수업이 있습니다. 그냥 /vendors 또는 /libs 디렉토리에 파일을 팝업 App::import을 사용하여 파일을로드합니다. "('LDAP', '해방') 앱 :: 가져 오기;"

+0

나는 libs와 폴더에 내 ldap.php을 넣어 넣어이다 내가 어떤 페이지를 호출 할 때 내 users_controller.php에,하지만 난 얻을 "C에서 구문 오류, 예기치 못한 T_STRING, 기대 T_FUNCTION : 구문 분석 오류 \ XAMPP \ htdocs를 \ timetracker \ 컨트롤러 \ users_controller.php 6 행의" – lanrat

+2

잘 @mrlanrat, 어딘가에 ** 구문 오류 **가 있습니다.이 오류는 Cake의 libs 나 공급 업체와 관련이 없습니다. – deceze

+0

코드를 게시하면 도움을받을 수 있습니다! – Leo

2

내가 그것을 작동 가지고, 내가 전화를했다 컨트롤러 클래스 외부에서 호출 한 다음 원하는 함수 내에서 새 클래스로 호출합니다. "응용 프로그램 : 수입 ('해방', 'LDAP를');"다음

는 최종 결과

<?php 
App::import('Lib', 'ldap'); 
class UsersController extends AppController { 

    var $name = 'Users'; 

    function index() { 
     $this->User->recursive = 0; 
     $this->set('users', $this->paginate()); 
    } 

     function login() { 

      if (!empty($this->data)) { 
       $ldap = new ldap; 
        if ($ldap->auth($this->data['User']['user'],$this->data['User']['password'])) { 

          if (!$this->User->findByUser($this->data['User']['user'])) 
          { 
           $ldap_info = $ldap->getInfo($this->data['User']['user']); 
           $this->data['User']['name'] = $ldap_info['name']; 
           $this->add(); 
          } 

          $this->Session->write('user', $this->data['User']['user']); 
          $this->redirect(array('action' => 'index')); 
        } else { 
          $this->Session->setFlash(__('Login Failed', true)); 
        } 
      } 
     } 

     function logout() { 
      $this->Session->delete('user'); 
      $this->redirect($this->referer()); 

     } 

    function view($id = null) { 
     if (!$id) { 
      $this->Session->setFlash(__('Invalid user', true)); 
      $this->redirect(array('action' => 'index')); 
     } 
     $this->set('user', $this->User->read(null, $id)); 
    } 

    private function add() { 
     if (!empty($this->data)) { 
      $this->User->create(); 
      if ($this->User->save($this->data)) { 
       $this->Session->setFlash(__('The user has been saved', true)); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); 
      } 
     } 
     $projects = $this->User->Project->find('list'); 
     $this->set(compact('projects')); 
    } 

    function edit($id = null) { 
     if (!$id && empty($this->data)) { 
      $this->Session->setFlash(__('Invalid user', true)); 
      $this->redirect(array('action' => 'index')); 
     } 
     if (!empty($this->data)) { 
      if ($this->User->save($this->data)) { 
       $this->Session->setFlash(__('The user has been saved', true)); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); 
      } 
     } 
     if (empty($this->data)) { 
      $this->data = $this->User->read(null, $id); 
     } 
     $projects = $this->User->Project->find('list'); 
     $this->set(compact('projects')); 
    } 

    function delete($id = null) { 
     if (!$id) { 
      $this->Session->setFlash(__('Invalid id for user', true)); 
      $this->redirect(array('action'=>'index')); 
     } 
     if ($this->User->delete($id)) { 
      $this->Session->setFlash(__('User deleted', true)); 
      $this->redirect(array('action'=>'index')); 
     } 
     $this->Session->setFlash(__('User was not deleted', true)); 
     $this->redirect(array('action' => 'index')); 
    } 
} 
?> 
관련 문제