Welcome Guest, Not a member yet? Register   Sign In
norecord case returning from model to controller-view. thanks!!! appreciate!
#1

[eluser]artlover[/eluser]
Hi, here is my model. I want to display an upload form at view if there is no record. what can I return to controller for no record case? now i made a silly $data[] = 0. and i have no control at viewer to create an if condition for upload form :/

appreciate helps!! thanks


Code:
function get_img_id_record($id_work) {
        
        $q_image = $this->db->getwhere('works_image', array('id_work' => $id_work));
        
        if($q_image->num_rows() > 0) {
            // record case
            foreach ($q_image->result() as $row) {
                $data[] = $row;
            }
        } else {
            // no record case
            $data[] = 0;
        }
        
        return $data;
        
    }
#2

[eluser]wowdezign[/eluser]
I usually do something like:

Code:
function get_img_id_record($id_work) {
        
        $q_image = $this->db->getwhere('works_image', array('id_work' => $id_work));
        
        if($q_image->num_rows() > 0) {
            // record case
            foreach ($q_image->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }else{
            return false;
        }
        
                
    }
#3

[eluser]wowdezign[/eluser]
Then in your controller you can do something like:

Code:
if($this->ModelName->get_img_id_record('id_number')){
      // show the results
}else{
      // display the form
}

If I understood you correctly that is.
#4

[eluser]artlover[/eluser]
yes thats working great Big Grin thanks!!

ps, how can I return num_rows from same model? with a different array like $data_num[]? or any better way?

thanks!!!
#5

[eluser]artlover[/eluser]
is there any way to return a string from model to view?

for example I have $str=2 at model, and how can I pass this string to view?
#6

[eluser]wowdezign[/eluser]
Without seeing the whole model it's hard to tell what's actually happening in the code, but one way is to assign the string to a member variable of the model and then write a method that returns the value of that member variable.

Code:
class SomeModel extends Model(){
    
    var $stringToReturn;

    function SomeModel(){
        parent::Model();
    }

    function theMethodYouCurrentlyHave(){
        // Doing some stuff and creating a string
        $this->stringToReturn = '2';
    }

    function getStringToReturn(){
        return $this->stringToReturn;
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB