Welcome Guest, Not a member yet? Register   Sign In
invoke controll from view?
#11

[eluser]Smy[/eluser]
controller: news.php

Code:
function index()
    {
        $this->load->model('NewsModel','newsObj');
        $result['news'] = $this->newsObj->getNews(); // function to retrieve the news
        $this->load->view('news', $result);
    }


Model : newsModel.php

Code:
function getNews(){
        $sql="SELECT * FROM tb_news";
        $result = $this->db->query($sql);
        $res=$result->result();
        
        return $res;
    }

function getAttachment($newsID){
        $sql="SELECT * FROM tb_attachment where newsId = $newsID";
        $result = $this->db->query($sql);
        $res=$result->result();
        
        return $res;
    }

view: news.php

Code:
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
foreach ($news as $row)
{
    echo $row->chvNewsTitle;
    echo br(1);
  
}

If i need to display the attachment along with the news Title, how can i call the model getAttachment($row->newsID) from my view
#12

[eluser]oldmatt[/eluser]
Again, your view should present data not manage it.

You could have the model perform the operation or the controller, but the view is for displaying. The simple rule is: you should not have anything in your views except if statements and foreach loops.
#13

[eluser]InsiteFX[/eluser]
You should be doing this in your Model or Controller not in a view!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB