InsideDarkWeb.com

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

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";
        }
  }

Stack Overflow Asked by user12332313 on November 18, 2021

1 Answers

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!

Related Questions

Strange igraph behaviour, generating duplicate vertices

1  Asked on January 15, 2021 by simon-mills

   

C++ printing float as nan

1  Asked on January 14, 2021 by acarter

     

Webclient isn’t dowloading everything from URL c#

1  Asked on January 14, 2021 by shynex

       

How to change the entire div content on button click

2  Asked on January 14, 2021 by liel-barouch

   

Sorting and paging nested documents

2  Asked on January 14, 2021 by taras-kohut

 

How to adjust for loop so that it prints list only once?

1  Asked on January 14, 2021 by benito-cano

         

Pygame doesn’t play mp3 files tagged with mutagen

1  Asked on January 14, 2021 by droptop

       

Average by group for ‘n’ number of rows per group – R

2  Asked on January 14, 2021 by codemaster

       

Non consecutive combinations of array elements in R

4  Asked on January 13, 2021 by guest2341

 

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.