2011-02-07 12 views
0

私はコハナコントローラを作成していますが、私は常にうんざりなエラーが発生しています。ビューの誤ったインスタンス化に関するものですが、どこにあるのかわかりません。私のコントローラ:ビューの問題の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); 
     } 

    } 

    } 

及び持続エラー: Kohana_View_Exception [0]:要求された図1

を発見できなかった理由これは、とすることができます?

は、問題が$view->render(TRUE);である。これはKohana2構文ですが、Kohana3で、レンダリングするためのパラメータは、エラー(true => 1)を引き起こし、ビュー名であるあなたに

+0

これはKohana v2またはKohana v3のですか? v3の場合、間違ったドキュメントを見ているので、[v3 docs](http://kohanaframework.org/guide)を読んでいるはずです。 – shadowhand

答えて

1

ありがとうございます。

関連する問題