TransWikia.com

General error Telecom doesn't have a default value with function in model

Stack Overflow Asked by user12332313 on November 18, 2021

I’m trying to achieve by sorting it if it is a different telecom, but it doesn’t work. Thank you in Advance. Anyways this is my code.

If you have any questions please ask me based on that I can share more details.

Controller:

$contact->telecom = getPhoneType();

Model:

 public function getPhoneType() {

        $s = substr($this->mobile, 0, 5);
        if ($s == "63905") {
            return "Globe";
        }

        if ($s == "63907") {
            return "Smart";
        }

        if ($s == "63922") {
            return "Sun Cellular";
        }
  }

One Answer

The problem seems to be with the model because it is returning value in three cases:

Solution 1:

//return some default value if none of the if condition works:
public function getPhoneType() {

        $s = substr($this->mobile, 0, 5);
        if ($s == "63905") {
            return "Globe";
        }

        if ($s == "63907") {
            return "Smart";
        }

        if ($s == "63922") {
            return "Sun Cellular";
        }

        return "Some default value";
  }

Solution 2:

Handle this on controller side:

$phone_type = getPhoneType();
$contact->telecom = isset($phone_type) ? $phone_type : "default value" ;

Solution 3:

Presently you might be having your column like this: telecom structure

Click on Change and then set some default value

setting default value

Try one of the above solution!! It should work.

Answered by Ankit Jindal on November 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP