-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9087 from kenjis/docs-upgrade-model
docs: improve Upgrade Models sample code
- Loading branch information
Showing
4 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use CodeIgniter\Model; | ||
|
||
class NewsModel extends Model | ||
{ | ||
// Sets the table name. | ||
protected $table = 'news'; | ||
|
||
// Sets the field names to allow to insert/update. | ||
protected $allowedFields = ['title', 'slug', 'text']; | ||
|
||
public function setNews($title, $slug, $text) | ||
{ | ||
$data = [ | ||
'title' => $title, | ||
'slug' => $slug, | ||
'text' => $text, | ||
]; | ||
|
||
// Uses Model's`insert()` method. | ||
return $this->insert($data); | ||
} | ||
} |
16 changes: 9 additions & 7 deletions
16
user_guide_src/source/installation/upgrade_models/ci3sample/001.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
class User_contact extends CI_Model | ||
class News_model extends CI_Model | ||
{ | ||
public function insert($name, $address, $email) | ||
public function set_news($title, $slug, $text) | ||
{ | ||
$this->db->insert('user_contacts', array( | ||
'name' => $name, | ||
'address' => $address, | ||
'email' => $email, | ||
)); | ||
$data = array( | ||
'title' => $title, | ||
'slug' => $slug, | ||
'text' => $text, | ||
); | ||
|
||
return $this->db->insert('news', $data); | ||
} | ||
} |