简体   繁体   English

Kohana API浏览器

[英]Kohana API Browser

I am new to kohana since i was used to codeigniter. 我是kohana的新手,因为我习惯于进行代码点火。 I have to admit that kohana has lot of interesting stuff that i want to know deeply and it seems to be a step over ci, in almost everything, ofc this is my opinion. 我必须承认,kohana有很多我想深入了解的有趣东西,这似乎比ci迈出了一大步,这几乎是我的观点。 One thing i really appreciated is the auto generated api browser, if it would works!!! 我真的很感激的是自动生成的api浏览器,如果可以的话!!! I extended the HTML "helper" class in this way: 我以这种方式扩展了HTML“ helper”类:

<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Extend HTML helper
 */
class HTML extends Kohana_HTML
{
    /**
     * HTML Wrapper for messages
     *
     * @param string message content
     * @param string message author 
     * @param int message timestamp
     * @return string
     * @uses HTML::chars
     * @uses Date::fuzzy_span
     */
    public static function message( $content, $author, $timestamp )
    {
        $formatted = '<div class="message">';
        $formatted .= self::chars( $content );
        $formatted .= '<span class="author">' . self::chars( $author ) . '</span>';
        $formatted .= '<span class="published">' . Date::fuzzy_span( $timestamp ) . '</span>';
        $formatted .= '</div>';
        return $formatted;
    }

}

I wrote that stuff in /application/classes/html.php When i go into the userguide and then api browser, i see the list of classes and HTML is there, with my new method also there. 我在/application/classes/html.php中写了这些东西。当我进入用户指南然后进入api浏览器时,我看到了类和HTML的列表,还有我的新方法。 If I click on the link i just get a blank page and this behavior doesn't change even if i click on another class/method. 如果我单击链接,我只会得到一个空白页,即使我单击另一个类/方法,此行为也不会改变。

If i remove all the content of my html.php file then all the api browser seems to work again!! 如果我删除了我的html.php文件的所有内容,那么所有的api浏览器似乎都可以再次使用!! I already search on the web for this problem but i did not find any results. 我已经在网上搜索了此问题,但未找到任何结果。 Can you help me to figure out a solution? 您能帮我找出解决方案吗? Tnx in advance 提前发送

Also you shouldn't use HTML in controllers... It's better to set a parent class that loads different partials or to set the message directly in the template and do 另外,您不应该在控制器中使用HTML ...最好设置一个加载不同部分的父类,或者直接在模板中设置消息并执行

<?php if ($message):?>
<div class="message">
<?=$message?>
<span class="author"><?=$author?></span>
<span class="published"><?=Date::fuzzy_span( $timestamp )?></span>';
</div>
<?php endif;?>

It makes it easier for others to read your code, and when working with others they'll understand your code better easier. 它使其他人更容易阅读您的代码,与他人一起工作时,他们会更轻松地理解您的代码。 Also - Check out the coding conventions on kohanas coding convention section 另外-在kohanas 编码约定部分中查看编码约定

Sorry guys but investigating I saw that the html.php file SHOULD NOT be put in the controller dir, instead it MUST be put in classes dir, sorry for that, i'm not used to have a classes dir in CI so i completely forget there is that dir lol! 抱歉,伙计们但是调查了一下,我发现html.php文件不应该放在控制器目录中,相反,它必须放在类目录中,对此感到抱歉,我不习惯在CI中使用类目录,所以我完全忘记了有那个大声笑! Hope it could help somebody else that is "blind" like me! 希望它可以帮助像我这样“盲”的人!

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

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