-2

I'm learning PHP: separation of concerns, MVC, functions, arrays, the works. I'm lost right now, admittedly.

I am using an existing authentication framework:

https://github.com/panique/huge/
// app/core/View.php 
/**
 * Class View
 * The part that handles all the output
 */
class View
{
    /**
     * simply includes (=shows) the view. this is done from the controller. In the controller, you usually say
     * $this->view->render('help/index'); to show (in this example) the view index.php in the folder help.
     * Usually the Class and the method are the same like the view, but sometimes you need to show different views.
     * @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
     * @param array $data Data to be used in the view
     */
    public function render($filename, $data = null)
    {
        if ($data) {
            foreach ($data as $key => $value) {
                $this->{$key} = $value;
            }
        }

        require Config::get('PATH_VIEW') . '_templates/header.php';
        require Config::get('PATH_VIEW') . $filename . '.php';
        require Config::get('PATH_VIEW') . '_templates/footer.php';
    }

Above is a note to inform you about the View class.

In my IndexCotroller:

public function index()
    {
        $this->View->render('index/index', array(
            'images' => ImagesModel::getImages())
        );
    }

In my ImageModel:

class ImageModel
{
    /**
     *
     *
     */
    public static function getImages($xxx)
    {
        $xxx = "test test test";
    }
}

In index/index view I have:

<?php $this->images; ?>

I get an error such as:

Warning: Missing argument 1 for ImageModel::getImages(), called in IndexController.php on line 21 and defined in ImageModel.php on line 13

I simply want to echo a variable to test that I can get data from my model onto my index view. I am very new to PHP, certainly have bitten off more than I can chew but this challenging me and have to know.

Are my functions and arrays wacky? Flame me, but provide knowledge too?!

tereško
  • 58,060
  • 25
  • 98
  • 150
The Dude man
  • 383
  • 6
  • 19
  • 1
    `images; ?>` should that be an echo? as it stands it seems to do nothing – RiggsFolly Mar 02 '17 at 00:42
  • 1
    `ImagesModel::getImages()` you defined the method with a parameter! But you are not passing one on this call. _Should that method be `return`ing something rather than setting `$xxx = somthing_ – RiggsFolly Mar 02 '17 at 00:43
  • 1
    _I simply want to echo a variable to test that I can get data from my model onto my index view_ Replace `$xxx = "test test test";` with `return "test test test";` And at least for now, loose the parameter on that method – RiggsFolly Mar 02 '17 at 00:47
  • 1
    @RiggsFolly Honestly, I didnt plagiarise you. So for the sake of my reputation, I will kindly delete my answer. But please, do provide and answer, and I will upvote you myself. – EddyTheDove Mar 02 '17 at 01:03
  • 1
    @EddyTheDove Well if thats the case undelete your answer and I will remove my comments – RiggsFolly Mar 02 '17 at 01:05
  • Took a moment but I see now. Thank you so much. Okay I can sanely get back to the docs! – The Dude man Mar 02 '17 at 01:18

1 Answers1

0

Well, first of all, you are not returning something from ImagesModel::getImages() so that value won't be set. Second, you are not passing the parameter in getImages() but you have this in ImageModel. So you should return some image from getImage() and remove that parameter (or pass parameter value, keeping parameter) to make it work.

Nitesh Verma
  • 2,460
  • 4
  • 20
  • 36