CodeIgniter Forums
Query Builder need help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Query Builder need help (/showthread.php?tid=79041)



Query Builder need help - zdarin - 04-12-2021

Hello,

i cant understand how pass data from controller to model query builder for example
i want get one contact card view by query builder where('id', $findid) how pass $findid variable?
or i should this done in controller?


and second question this below as example written is query builder example or not? If yes why no connection to DB and its working?
PHP Code:
    public function getNews($id false)
    {
        if ($id === false)
        {
            return $this->findAll();
        }

        return $this->asArray()
                    ->where()
                    ->first();
    



RE: Query Builder need help - kenjis - 04-12-2021

It is not a Query Builder example. It is an example of CodeIgniter\Model.

But it is very confusing because CodeIgniter\Model could use Query Builder's methods.


RE: Query Builder need help - zdarin - 04-12-2021

(04-12-2021, 10:34 PM)kenjis Wrote: It is not a Query Builder example. It is an example of CodeIgniter\Model.

But it is very confusing because CodeIgniter\Model could use Query Builder's methods.
OK thanks for understand of query builder, maybe you know how i can send $var to query builder?

I want to do that in Contacts page i see all contacts its ok and working but i need make on click button to show only one contact card i think i make onclick send $var to query buuilder where('id', $id) and get only one contact card, but i cant understand how to do and correct do, because in controler i can make this working but i know its not correct

i need help how send $var from Controller to Model


RE: Query Builder need help - InsiteFX - 04-13-2021

Do it in the controller point your view button to the controller method and load the data
then send to a new single view.

Otherwise you will need to use jQuery ajax for this.


RE: Query Builder need help - kenjis - 04-13-2021

I recommend you read the User Guide:
https://codeigniter4.github.io/CodeIgniter4/tutorial/news_section.html#setting-up-your-model


RE: Query Builder need help - zdarin - 04-14-2021

(04-13-2021, 02:52 AM)kenjis Wrote: I recommend you read the User Guide:
https://codeigniter4.github.io/CodeIgniter4/tutorial/news_section.html#setting-up-your-model

Thanks for good way

i made by this and its working, one view but multiple way to get data

PHP Code:
    public function index($page 'page')
    {
        
        $contactcard_model 
= new ContactCard();
        $allcontactcard['contactcard'] = $contactcard_model->getAllContactCards();
        $contactcard['contactcard'] = $contactcard_model->find([2]);

        if ( ! is_file(APPPATH.'/Views/pages/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
        }

        $data 
        [
            'title' => $page,  
               
            
'contactcard'  => view('pages/contacts/contact_card'$contactcard),
            'allcontactcard' => view('pages/contacts/contact_card'$allcontactcard),

        ];  
         

        
echo view('pages/'.$page$data);