The second method in controller doesn't work PHP MVC

183

I have problem .Second method in controller does not to work .Output :undefined variable item. In construct method anything is work . I searched in google about this item but nothing found Please help me resolve this problem. Thanks advance.

Controller

require_once("model/Model.php");

class Controller
{   

    function __construct()
    {   

        $image = array();   
        $image = Model::selectAll();
        require_once("view/index.php"); 

    }

    public function actionCategory($param = 0)
    {       

        $item = Model::selectByName($param);
        require_once("view/index.php"); 

    }

}

Model

 class Model
{
    static public function selectAll()
    {


        $names = array("jhon" , "Hilary" , "Steven, "Jake");

        return $names;

    }

    static public function selectByName($param)
    {   

        $param = strval($param);

        $param = "Hilary";

        return $param;

    }
}

View

foreach($names as $key)
{
   print($key);
}

print($item);

People are also looking for solutions to the problem: php - Remove blank line from else statement

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.