Welcome Guest, Not a member yet? Register   Sign In
Good example of CRUD
#2

this is how i update in a model , to do with updating a blog article . If logged in then i can access simple menu, to pick blog i want to edit. Current data of blog is output to a form, to do the editing .

Form goes to a controller and gets the info i need. Final bit is where model does the updating
allowed field of model

Code:
class BlogModel extends Model

{

protected $table      = 'blog';
protected $primaryKey = 'Id';
protected $allowedFields = ['title','article','image','slug','date','context'];
protected $limit;
protected $offset;
protected $Id;
protected $title;
protected $article;
protected $slug;


Code:
public function amendBlog($blogId,$title,$article,$slug)
    
    
     {
    
     $this->Id= $blogId;
     $this->title=  $title;
     $this->article =  $article;
     $this->slug=$slug;
     $data =[
     'title'=>$this->title,
     'article'=>$this->article,
     'slug'=>$this->slug
     ];
   $logic=   $this->update($this->Id,$data);
   return $logic;
      
     }

but to be honest i don't like things being done for me, if i write my own code, at least i know how validating is done and whats involved
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply


Messages In This Thread
Good example of CRUD - by joho - 04-18-2023, 03:25 AM
RE: Good example of CRUD - by captain-sensible - 04-18-2023, 04:03 AM
RE: Good example of CRUD - by joho - 04-18-2023, 06:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB