Вопрос

I'm new to Kohana and I'm following this excellent tutorial. I am getting this cryptic error message

ErrorException [ 8 ]: Array to string conversion ~ SYSPATH\classes\Kohana\Log\Writer.php [ 81 ]

after trying to load this url

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

The problem seems to be originating from my Model_Article() because I get this error with only this line of code in it

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

        /*

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

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

I uncommented database and orm in application/bootstrap.php as suggested by the author.

Here is 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');      
    }

}

Here is 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(); ?>

And here is application/classes/Model/article.php

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

class Model_Article extends ORM {

}
Это было полезно?

Решение

This is a known issue when running PHP 5.4.12 and beyond. It has been fixed in 3.3.1.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top