• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query Builder need help

#1
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();
    
Reply

#2
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.
Reply

#3
(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
Reply

#4
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
I recommend you read the User Guide:
https://codeigniter4.github.io/CodeIgnit...your-model
Reply

#6
(04-13-2021, 02:52 AM)kenjis Wrote: I recommend you read the User Guide:
https://codeigniter4.github.io/CodeIgnit...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);

    
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.