mercredi 30 septembre 2015

Call to undefined function App\Http\Controllers\ [ function name ]

In my controller, I create a function getFactorial

public static function getFactorial($num)
{
    $fact = 1;
    for($i = 1; $i <= $num ;$i++)
        $fact = $fact * $i;
    return $fact;
}

Then, I use it like this

public function codingPuzzleProcess()
{

    $word     = strtoupper(Input::get('word'));
    $length   = strlen($word);
    $max_value = ($length * 26);
    $characters = str_split($word);

    $num = 1 ;
    $index = 1;

    sort($characters);

    foreach ( $characters as $character) {
        $num += getFactorial($index) * $index;
        $index ++;
    }

    return Redirect::to('/coding-puzzle')
        ->with('word', $word )
        ->with('num', $num )
        ->with('success','Submit successfully!');

}

For some reason, I keep getting this error

Call to undefined function App\Http\Controllers\getFactorial()

Can someone please teach me how to fix this error ?

Much appreciated in advance.


CodeController.php

<?php

namespace App\Http\Controllers;
use View, Input, Redirect;

class CodeController extends Controller {


    public function codingPuzzle()
    {
        return View::make('codes.puzzle');
    }

    public static function getFactorial($num)
    {
        $fact = 1;
        for($i = 1; $i <= $num ;$i++)
            $fact = $fact * $i;
        return $fact;
    }


    public function codingPuzzleProcess()
    {

        $word     = strtoupper(Input::get('word'));
        $length   = strlen($word);
        $max_value = ($length * 26);
        $characters = str_split($word);

        $num = 1 ;
        $index = 1;

        sort($characters);

        foreach ( $characters as $character) {
            $num += getFactorial($index) * $index;
            $index ++;
        }

        return Redirect::to('/coding-puzzle')
            ->with('word', $word )
            ->with('num', $num )
            ->with('success','Submit successfully!');

    }


}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1LkarZy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire