如何在cakephp 1.3中使用独立类?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何在cakephp 1.3中使用独立类?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个PHP编写的独立类,用于一些非常基本的LDAP / AD函数.我想在我正在使用cakePHP的项目中使用这个类.

它看起来像在cakePHP 1.2中我可以将该类添加为供应商,但看起来像cakePHP 1.3删除了对供应商的支持.那么我该如何从这个类中调用一些函数呢?

(我想尝试保持类本身相同而不是把它变成插件,因为这似乎是不必要的)

谢谢!

代码如下:

**<?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));
        }
    }
    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'));
}
}
?>**
Cake 1.3仍然完美支持供应商文件的想法.另外,他们 now also support “libraries”,额外的课程不是第三方课程.只需将文件弹出到/ vendors或/ libs目录,然后使用App :: import加载文件即可.

脚本宝典总结

以上是脚本宝典为你收集整理的如何在cakephp 1.3中使用独立类?全部内容,希望文章能够帮你解决如何在cakephp 1.3中使用独立类?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。