1

I have a model with two functions, like this:

<?php

class FotoModel extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function getFotosByCat($cat)
    {
        $this->load->helper("file");
        switch($cat)
        {
            case "bloemen" : return get_filenames("/images/foto/bloemen/");
            case "dieren" : return get_filenames("/images/foto/dieren/");
            case "andere" : return get_filenames("/images/foto/andere/");
        }
    }

    public function getFotoLinksByCat($cat)
    {
        $fileNames = getFotosByCat($cat);
        //i do stuff with $fileNames and provide a return statment..
    }
}

?>

I load the model in my controller and tested the second method with some static data for $fileNames and everything works fine. Only when I make a call to the first function (the one with the switch/case statement) from the second (as seen in the code-example) I get an error.

And the thing is I don't even get to see what kind of error. It is because of testing and trying that I know the error MUST be in the first function. Anyone that can help me to solve this one?

2
  • May be there is an error in get_filenames. Can you post that code? Commented Jul 27, 2011 at 18:59
  • @Sukumar get_filenames is a function from CI's file helper Commented Jul 27, 2011 at 20:42

2 Answers 2

2

Try:

$fileNames = $this->getFotosByCat($cat);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that I didn't see such an 'easy' mistake.. Thanks a lot! ;)
-1

I noticed in your switch you haven't used any break;'s

(im sorry im a SO n00b and I can't for the life of me figure out inline code span..)

1 Comment

Breaks are not needed when there's a return statement!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.