Laravel控制器认为我的功能未定义

Vin*_*nce 5 php laravel

很简单.我正试图从我的控制器中调用一个函数.事实上,该功能已定义.然而,当调用该函数时,我得到"PHP致命错误:调用未定义函数validate()..."

这是我的代码.有任何想法吗?谢谢.

<?php

class HomeController extends BaseController {

    /**
     * Controller for the index action of the home page.  Displays the landing page.
     */
    public function index()
    {
        return View::make('landing', array('success' => false));
    }

    /**
     * Controller to handle processing the contact form and re-displaying the landing page
     */
    public function processForm()
    {
        $form_array = array();
        $errors = array();

        foreach (array('email','fname','lname','message','newsletter') as $val)
        {
            if (isset($_POST[$val]))
                $form_array[$val] = $_POST[$val];
            else
                $form_array[$val] = null;
        }

        $form_ok = validate();

        if ($form_ok)
        {
            echo "GOOD!";
        }
        else
        {
            echo "BAD!";
        }
    }

    /**
     * Helper function for validating the form.  Returns true if the form was 
     * submitted without errors.
     */
    public function validate()
    {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

Jas*_*son 12

看起来你正试图打电话$this->validate(),而不是validate().你已经定义validate()为一个类方法,而不是一个独立的函数.