【问题标题】:Array to String Conversion Error - Kohana数组到字符串转换错误 - Kohana
【发布时间】:2013-09-08 17:45:37
【问题描述】:

我是 Kohana 的新手,我正在关注 this excellent tutorial。我收到这条神秘的错误消息

ErrorException [8]:数组到字符串的转换~ SYSPATH\classes\Kohana\Log\Writer.php [81]

尝试加载此网址后

http://localhost/kohana-blog/index.php/article/new

问题似乎源于我的Model_Article(),因为我收到此错误时只有这行代码

public function action_new() 
    {           
        $article = new Model_Article();

        /*

        $view = new View('article/edit');
        $view->set("article", $article);

        $this->response->body($view);
        */
    }

按照作者的建议,我在application/bootstrap.php 中取消了databaseorm 的注释。

这里是application/classes/Controller/Article.php

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Article extends Controller {

    public function action_index() 
    {
        $view = new View('article/index');
        $this->response->body($view);
    }

    // loads the new article form
    public function action_new() 
    {
        $article = new Model_Article();

        $view = new View('article/edit');
        $view->set("article", $article);

        $this->response->body($view);
    }

    // save the article
    public function action_post() 
    {
        $article_id = $this->request->param('id');
        $article = new Model_Article($article_id);

        // Populate $article object form 
        $article->values($_POST); 

        // Saves article to database
        $article->save();

        // Redirects to article page after saving
        $this->request->redirect('index.php/article');      
    }

}

这里是application/views/article/edit.php

<?php defined('SYSPATH') or die('No direct script access.'); ?>

<h1>Create new article</h1>

<?php echo Form::open('article/post/'.$article->id); ?>
    <?php echo Form::label("title", "Title"); ?>
    <br />
    <?php echo Form::input("title", $article->title); ?>
    <br />
    <br />
    <?php echo Form::label("content", "Content"); ?>
    <br />
    <?php echo Form::textarea("content", $article->content); ?>
    <br />
    <br />
    <?php echo Form::submit("submit", "Submit"); ?>
<?php echo Form::close(); ?>

这里是application/classes/Model/article.php

<?php defined ('SYSPATH') or die('No direct script access');

class Model_Article extends ORM {

}

【问题讨论】:

  • 看来我真的需要把教程更新到 KO 3.3

标签: php kohana kohana-3


【解决方案1】:

这是运行PHP 5.4.12 and beyond 时的一个已知问题。 It has been fixed in 3.3.1.

【讨论】:

    猜你喜欢
    • 2012-01-10
    • 2015-02-26
    • 2012-07-15
    • 2017-12-02
    • 2013-06-23
    • 2013-08-24
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多