Welcome Guest, Not a member yet? Register   Sign In
Can somebody help me please?
#1

[eluser]Christophe28[/eluser]
Hello,

I have a 2 variables which I have available in a method. I want to pass these to the model, but I don't know how.

I'm new in CI and OOP -> but I hope somebody can help me ...

For now I have:


Code:
function photo_view_function($username, $caption)
    {
        // loading the model
        $this->load->model('mediamanager_model', array('caption' => $caption, 'username' => $username));
        $data['photo'] = $this->mediamanager_model->getSinglePhoto();

        $data['caption'] = str_replace('_', ' ', $caption);

        $data['main_content'] = 'single_photo_view';
        $this->load->view('template', $data);

    }

And the model
Code:
function getSinglePhoto($username, $caption) {

        $this->db->get_where('mediamanager', array('caption' => $caption, 'username' => $username));    
        
        $sql = $this->db->get();

        $result = $sql->result();

        return $result;


    }

But no mather what I try, I get errors Sad

Can someone help me plz Smile

Thx!
#2

[eluser]WanWizard[/eluser]
Would help to know what the errors are...

For starters, you can not pass an array to $this->load-model. The second parameters should be a string defining an alternative object name.

Then you define the method getSinglePhoto() as having two parameters, yet when you call it no parameters are passed...
#3

[eluser]Christophe28[/eluser]
Hi,

Oops, I'm sorry. Here are the (many) errors:
Code:
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/Loader.php

Line Number: 155

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/Loader.php

Line Number: 184

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/Loader.php

Line Number: 185

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Photos::$mediamanager_model

Filename: controllers/photos.php

Line Number: 20

I'm really stuck here Sad Can you give me a small setup, hint, or even a link to a tutorial plz? I have searched things like 'passing data from controller to model' but can't find anything useful ...

Thank you for helping out!

Christophe
#4

[eluser]WanWizard[/eluser]
Did you even read past the first line of my answer?

You get the "Array to string conversion" error because you pass an array as parameter to the $this->load->model() loader, while it expects a string value there.

The CI online manual is excellent, I suggest starting there.
#5

[eluser]Christophe28[/eluser]
Yes, I knew that was giving an error, but I didn't know how to put those two parameters in one string, therefore asked for little help.

I already looked at database class in the userguide, but I'll take a closer look.
#6

[eluser]Christophe28[/eluser]
Ooh, found out what was going wrong. I'll post the solution when it is ready Smile

Thx!




Theme © iAndrew 2016 - Forum software by © MyBB