[eluser]gbar[/eluser]
Excuse me Toopay, I would like to take this opportunity to learn more
I can not understand a thing ....
in this code ....
Code: function _retrieveAuthors($sortBy, $sortOrder, $limit, $offset, $search, $field = '')
according to my modest knowledge, the variable $ field passed between the parentheses of the function, should lose the starting value and assume the new value, that is, ' ' ... nothing ....
How could later remember the primitive value in the operator ternary?
Quote:$key_field = $field == '' ? 'author' : $field;
Thanks
[eluser]toopay[/eluser]
As long as i remember, i was born on this planet. And there is no something you called "mysterious" in this thread, since the DB_active_rec class contain same variable with yours (take a look at InsiteFX comment). But as you can see, it is good practice to set an initial value on function parameter, and then inspect/validate that param before use it. That will prevent any error for you.
[eluser]gbar[/eluser]
I have read your answer, and I have also revised comment InsiteFX, that fact did not understand and still do not understand ...
Unfortunately my poor English and the translation of google, I do not help to understand the real meaning of your words ...
I read the guide several times, and now I just finished rereading the relevant part of the class active records, unfortunately this part of me is still obscure, maybe I have too many legacies of procedural programming, I deal with CodeIgniter by only one month ... undoubtedly soon will fill this gap.
Greetings
[eluser]toopay[/eluser]
At the class which i (and InsiteFX already) mention, $field variable is being used. Look at './system/database/DB_active_rec.php', you will found this section :
Code: /**
* Like
*
* Generates a %LIKE% portion of the query. Separates
* multiple calls with AND
*
* @access public
* @param mixed
* @param mixed
* @return object
*/
function like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'AND ', $side);
}
[eluser]gbar[/eluser]
Then you refer to a definite class, I thought the generic active records ...
now it makes me ask you a question, I hope is not stupid ...
if I had used another variable name, it would work now? was therefore a conflict? if instead of $field, I had already put in origin (form, controller and model) variable named $key_field (or any other word)?
It seems to me, among other things, to have tried to put a different name but with the same bad result ...
in all cases, this part of code was an implementation of a video tutorials ... now I'm rewriting everything from scratch to better assimilate ...
thanks for your time
[eluser]toopay[/eluser]
Did you try to use another name for that parameters? What CI version you used.
[eluser]gbar[/eluser]
I'm using the last version, CI 2.0.2
For example there are small things that I can not give me an explanation.
For example, if I write this, the page works:
Code: function authors($offset = '0')
{
$limit = '5';
$results = $this->authors_model->_retrieveAuthors($limit, $offset);
If I write it, does not work:
Code: function authors()
{
$limit = '5';
$offset = '0';
$results = $this->authors_model->_retrieveAuthors($limit, $offset);
I can not understand the difference, but I'll find out ...
[eluser]InsiteFX[/eluser]
Quote:If I write it, does not work:
Code: function authors()
{
$limit = '5';
$offset = '0';
$results = $this->authors_model->_retrieveAuthors($limit, $offset);
I can not understand the difference, but I’ll find out ...
Because $limit and $offset are integer values:
Code: /**
* Sets the LIMIT value
*
* @access public
* @param integer the limit value
* @param integer the offset value
* @return object
*/
$limit = 5;
$offset = 0;
$this->db->limit(5, 0);
InsiteFX
[eluser]gbar[/eluser]
You're right, it was a typing error put the quotes to the numbers ...
My question was different. Can you kindly explain to me, what is the difference between initialize variables between the parentheses of a called function, and initialize them inside the same function ...
Let me explain, this code does not work well:
Code: function authors()
{
$limit = 5;
$offset = 0;
$results = $this->authors_model->_retrieveAuthors($limit, $offset);
This works rather well.
Code: function authors($offset = 0)
{
$limit = 5;
$results = $this->authors_model->_retrieveAuthors($limit, $offset);
But we are talking about two variables, both enter into the function of a model ...
I do not understand the difference.
thanks
|