View 视图问题的Kohana控制器实例化

View 视图问题的Kohana控制器实例化,view,kohana,instantiation,View,Kohana,Instantiation,我正在编写一个kohana控制器,我经常会遇到一个奇怪的错误,我想这是关于视图的一个错误实例化,但我不知道它在哪里。我的控制器: <?php if (!defined('SYSPATH')) exit('No direct script access allowed'); /** * Contact_Controller - Used for validating and sending emails from form. * */ class Controller_Con

我正在编写一个kohana控制器,我经常会遇到一个奇怪的错误,我想这是关于视图的一个错误实例化,但我不知道它在哪里。我的控制器:

<?php if (!defined('SYSPATH')) exit('No direct script access allowed');
/**
  * Contact_Controller - Used for validating and sending emails from form.
  *
  */
  class Controller_Contact extends Controller
  {

  //    public function __construct()
    //{
        //parent::__construct();
    //}

    public function action_index()
    {
        //Setup view without rendering
        //Setup base view
        $view = new View('template');

        //Setup header
    //  $view->header = new View('header');

        //Setup header title
        //$view->header->title = 'Kohana Contact Form by Drew Douglass';

        //Setup content view
        $view->content = new View('contact');

        //Setup footer view
        //$view->footer = new View('footer');

        //Setup default form values so we can repopulate the form
        $form = array
        (
            'contact_name' => '',
            'contact_email' => '',
            'contact_subject' => '',
            'contact_message' => ''
        );

        //copy the form fields into the errors for later...
        $errors = $form; 

        //Check to see if the form was submitted
        if(isset($_POST['contact_submit']))
        {
            //Add the rules we need to validate our form
            $post = new Validation($_POST);

            //filter the whitespace from beginning and ends of fields
            $post->pre_filter('trim');

            //Add rules for contact_name
            $post->add_rules('contact_name', 'required', 'standard_text', 'length[2,20]');

            //Add rules for contact_email
            $post->add_rules('contact_email', 'required', 'email', 'email_domain');

            //add rules for subject
            $post->add_rules('contact_subject', 'required', 'length[5,30]', 'standard_text');

            //Add rules for message
            $post->add_rules('contact_message', 'required', 'standard_text');

            //If there were no errors...
            if($post->validate())
            {
                //Load the config file with our email address defaults
                //This make our app more portable
                $email_config = Kohana::config_load('email');

                //Send it and render the view with message.
                $to = $email_config['default_email'];
                $from = $this->input->post('contact_email');
                $subject = $this->input->post('contact_subject');
                $message = $this->input->post('contact_message');

                //Add some info to the end of the message for reference
                $message .= "\n\n This message was sent to you from".$this->input->post('contact_name')." and the email given is ".$from;

                if(email::send($to, $from, $subject, $message, TRUE))
                {
                    $view->content->set('form_values', $form);
                    $view->content->set('message', 'Your email was sent!');
                    $view->render(TRUE);
                }
                else
                {
                    die('We had a technical error, please try again.');
                }
            }

            //else we got errors...
            else
            {
                //repopulate form values
                $form = arr::overwrite($errors, $post->as_array());

                //setup the errors
                $errors = arr::overwrite($errors, $post->errors('form_errors'));

                //pass the form values and errors to the view
                $view->content->set('errors', $errors);
                $view->content->set('form_values', $form);

                //Render the view with errors and values
                $view->render(TRUE);
            }

        }
        //form was not submitted, just show it.
        else
        {
            $view->content->set('form_values', $form);
            $view->render(TRUE);
        }

    }

  }

问题在于
$view->render(TRUE)这是Kohana2语法,但在Kohana3中,要呈现的参数是视图名称,导致错误(
true=>1
)。

这是针对Kohana v2还是Kohana v3的?如果是v3,那么您查看的文档是错误的,您应该阅读。