Welcome Guest, Not a member yet? Register   Sign In
Why are we saying SLUG = FALSE?
#2

1. http://php.net/manual/en/functions.argum...ts.default
A function/method may define default values for arguments, in this case, the default value of $slug is FALSE. If you call get_news() without supplying an argument, $slug will be FALSE.

2. http://php.net/manual/en/function.return.php
Since the last statement inside the curly braces for the if statement is
Code:
return $query->result_array();
, nothing outside the curly braces will be executed if $slug === FALSE

3. Yes, unless you change the code outside the curly braces to change the return type and only set the where clause when $slug !== FALSE. For example:

PHP Code:
public function get_news($slug FALSE)
{
    
$returnMethod 'result_array';
    if (
$slug !== FALSE) {
        
$this->db->where('slug'$slug);
        
$returnMethod 'row_array';
    }
    
    
$query $this->db->get('news');
    return 
$query->{$returnMethod}();


Since this is probably more confusing than the original code, you're probably better off with what you already have.
Reply


Messages In This Thread
Why are we saying SLUG = FALSE? - by lexxtoronto - 03-18-2015, 01:12 PM
RE: Why are we saying SLUG = FALSE? - by mwhitney - 03-18-2015, 01:25 PM
RE: Why are we saying SLUG = FALSE? - by CroNiX - 03-18-2015, 02:27 PM
RE: Why are we saying SLUG = FALSE? - by mwhitney - 03-19-2015, 08:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB