Kohana API 浏览器
我对 kohana 很陌生,因为我习惯了 codeigniter。我不得不承认,kohana 有很多有趣的东西,我想深入了解,它似乎比 ci 更进一步,几乎在所有方面,ofc 这是我的观点。我真正欣赏的一件事是自动生成的 api 浏览器,如果它能工作的话!我以这种方式扩展了 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;
}
}
我在 /application/classes/html.php 中编写了这些内容 当我进入用户指南,然后进入 api 浏览器时,我看到类列表和 HTML 都在那里,我的新方法也在那里。如果我单击该链接,我只会得到一个空白页面,即使我单击另一个类/方法,这种行为也不会改变。
如果我删除 html.php 文件的所有内容,那么所有 api 浏览器似乎都能再次工作!我已经在网上搜索了这个问题,但没有找到任何结果。 你能帮我想出解决办法吗?提前Tnx
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,但是调查后我发现 html.php 文件不应该放在控制器目录中,而必须放在类目录中,对此感到抱歉,我不习惯在 CI 中使用类目录,所以我完全忘记了有那个目录哈哈!希望它可以帮助像我一样的“盲人”!
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!
另外你不应该在控制器中使用 HTML...
最好设置一个加载不同部分的父类,或者直接在模板中设置消息并执行
它,这样其他人更容易阅读您的代码,并且在与其他人合作时,他们会更容易地理解您的代码。
另外 - 查看 kohanas 上的编码约定 编码约定部分
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
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