简体   繁体   中英

Kohana API Browser

I am new to kohana since i was used to codeigniter. 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. One thing i really appreciated is the auto generated api browser, if it would works!!! I extended the HTML "helper" class in this way:

<?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. 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!! 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

<?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

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! Hope it could help somebody else that is "blind" like me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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