samuel toh samuel toh - 4 months ago 9
PHP Question

How to send a parameter from the controller to a model with a number of different parameters?

My controller is like this :

function a()
{
...
$notification = $this->notification_model->get_notification($session['customer_id'], 10);
...
}

function b()
{
...
$new_notification = $this->notification_model->get_notification($session['customer_id'], 1, "notification_new");
...
}


My model is like this :

function get_notification($customer_id, $limit, $is_notif)
{
...
}


The number of parameters passed :

In function a : 2 parameter

In function b : 3 parameter

In function(model) : 3 parameter


When executed, there exist error like this : Message: Missing
argument 3 for....


This is because different parameters

Any soluton to solve my problem?

Answer

In model function you can set the third parameter default value as null

function get_notification($customer_id, $limit, $is_notif=null)

Read http://php.net/manual/en/functions.arguments.php

Comments