Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Usually it's better for functions to have one job. Your get_biography() function has 2: get one biography and get all biographies. Consider splitting them up into 2 functions. Also there's no need for the multiple db access.</p> <pre><code>public function get_biography($id=null) { $this-&gt;db-&gt;where('id', $this-&gt;get_property($id)) $query = $this-&gt;db-&gt;get('biography_content'); foreach($query-&gt;row() as $key =&gt; $value) { $this-&gt;set_property($key, $value); } } public function get_biographies() { $biography_list = array(); // don't limit this query to just id's - get everything $query = $this-&gt;db-&gt;get('biography_content'); // For each record, return a new biography_model object foreach($query-&gt;result() as $row) { $model = new biography_model(); // set the properties you already have straight onto the new model // instead of querying again with just the id foreach($row as $key =&gt; $value) { $model-&gt;set_property($key, $value); } $biography_list[] = $model; } return $biography_list; } </code></pre> <p>Also you might want to take advantage of php's <code>__get</code> and <code>__set</code> magic methods:</p> <pre><code>public function __get($property) { if(!isset($this-&gt;$property)) return null; return $this-&gt;$property; } public function __set($property, $value) { if(!property_exists($this, $property)) return; if($property == 'image_file_name') { $this-&gt;image_url = $this-&gt;get_bio_img_url($value); } else $this-&gt;$property = $value; } </code></pre> <p>This will let you get properties on your model like this: <code>$bio-&gt;title</code> instead of <code>$bio-&gt;get_property('title')</code> while at the same time provide a place you can introduce new logic later.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload