简体   繁体   English

在Kohana 3中使用自定义类

[英]Using custom classes in Kohana 3

Hey, I'm creating a Call of duty 4 Server Watcher in Kohana 3, and I had created the basic classes for it before: 嘿,我在Kohana 3中创建了一个Call of Duty 4 Server Watcher,并且之前已经为它创建了基本类:

  1. A static Socket class (for handling basic network commands) 静态Socket类(用于处理基本的网络命令)
  2. A Cod4Socket class, (which uses the previously mentioned Socket class) that provides wrapper functions for basic commands. 一个Cod4Socket类(使用前面提到的Socket类),为基本命令提供包装函数。

What I want is to be able to use said classes inside the controllers for the website. 我想要的是能够在网站的控制器内使用上述类。

Where am I supposed to put the class files, where should I "include" them, and how do I use them? 我应该将类文件放在哪里,应该在哪里“包含”它们,以及如何使用它们?

Edit: I'm using Kohana 3. 编辑:我正在使用Kohana 3。

Where am I supposed to put the class files? 我应该将课程文件放在哪里?

Add your class files into the application/classes/ directory with lowercase filenames. 用小写的文件名将类文件添加到application / classes /目录中。

  • Socket should go into application/classes/socket.php Socket应该进入application/classes/socket.php
  • Cod4Socket should go into application/classes/cod4socket.php Cod4Socket应该进入application/classes/cod4socket.php

Where should I "include" them, and how do I use them? 我应该在哪里“包括”它们,以及如何使用它们?

There is no need to manually include them; 无需手动添加它们; simply use them as if they were already included. 只需使用它们,就好像它们已经包含在内一样。 The Kohana autoloader will find the classes if they're in the right files. 如果它们在正确的文件中,则Kohana自动加载器会找到这些类。

Additional Info: 附加信息:

Sometimes, you want to place your custom classes in a place like this 有时,您想将自定义类放在这样的地方

application/
    classes/
        controllers/
            .......
        models/
            ......
        etc/
            CustomClassFirst.php
            CustomClassSecond.php

You can call these classes by 您可以通过以下方式调用这些类

$customClassOne = new Etc_CustomClassFirst();

and then redefine the class name into this 然后将类名重新定义为

class Etc_CustomeClassFirst {}

Did it on my own: http://www.dealtaker.com/blog/2010/06/02/kohana-php-3-0-ko3-tutorial-part-9/ 是我自己完成的吗: http : //www.dealtaker.com/blog/2010/06/02/kohana-php-3-0-ko3-tutorial-part-9/

You have to include the files in the bootstrap.php file, and then just call it normally on your controller. 您必须将文件包括在bootstrap.php文件中,然后在控制器上正常调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM