Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>observation: do you notice how this line keeps getting repeated over and over </p> <pre><code> $this-&gt;input-&gt;post('customer_code') ; </code></pre> <p>suggestion: never use $this->input->post or anything like it inside database insert or update. just pass in variables or arrays that have been filtered, cleansed, validated and are ready to go. </p> <pre><code> // adding TRUE enables xss clean $customerCode = this-&gt;input-&gt;post('customer_code', TRUE) ; </code></pre> <p>now you can use $customerCode for any method - it will be clearer and easier to read - and if the form name changes - you only have to change it one place. and for a bonus we added xss cleaning. if you need to use it in more then one method: </p> <pre><code> $this-&gt;customerCode = this-&gt;input-&gt;post('customer_code', TRUE) ; </code></pre> <p>now $this->customerCode will be available to any method in the class. </p> <p>===== edit <em>"What is the meaning it will be available to any method in the class?"</em> well -- that is the really cool thing about $this-> normally in a method (function) when you set a variable: $myvariable, you can only use it within the method. when you use $this->myvariable its instantly available to any method in the class. </p> <p>which is cool but whats SUPER COOL, is that you can set $this->variable in your model constructer - such as the name of your database table, fields, etc. like $this->dbtable = 'acme_users'; $this->dbfields = 'id,first,last,email';</p> <p>then you can use generic code like $this->dbtable, $this->dbfields in your methods. Another advantage is that you can <strong>put very specific knowledge about your model up top in the constructor - and then be more abstract in the method code you write</strong>. that makes it easier to reuse / extend. </p>
 

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