Welcome Guest, Not a member yet? Register   Sign In
Make link generator
#1

Hi,
I want to make link generator then i'll use it for generate QR-Code image.
i've created it already but i think it's not a good way to generate it
Code:
public function linkGenerate()
    {
        $id = $this->confirmModel->select('TRACKID')->findAll();
        $url = [];
            foreach ($id as $ids) {
                $link['id'] = base_url($ids);
                $url [] = $link;
            }
        return $url;
    }

when i dump the url field, it will show array like:
https://localhost:8080/index.php/1
https://localhost:8080/index.php/2
and so on

i getting struggle when i want to add any segment before track id like https://localhost:8080/index.php/user/1

any suggestion the better way to generate this url? 

thanyou
Reply
#2

PHP Code:
$link['id'] = base_url('user/'.$ids); 
Reply
#3

(12-01-2021, 05:12 PM)kenjis Wrote:
PHP Code:
$link['id'] = base_url('user/'.$ids); 

it's show array of string exception
Reply
#4

Do you mean "Array to string conversion"?
If so, just to add code to process to get string from an array.
Reply
#5

(12-01-2021, 07:36 PM)kenjis Wrote: Do you mean "Array to string conversion"?
If so, just to add code to process to get string from an array.

yes array to string conversation, which array I have to get it string? url or id?
i have no idea
Reply
#6

You can know the type of a variable with dd($variable).
Reply
#7

(12-01-2021, 08:00 PM)kenjis Wrote: You can know the type of a variable with dd($variable).

still not solved, i have dd() it but i have no idea how to solve this array to string conversion
Reply
#8

PHP Code:
Maybe this will help you?

# CONTROLLER
public function linkGenerate()
{
    $urls = [];
    
    $results 
$this->confirmModel->select('TRACKID')->findAll();
    
    
foreach ($results as $result) {
         $urls[$result] = base_url('user/'.$result);
    }

    return $urls;
}


// VIEW
dd($urls);

Will give you array structure like this

array (
 
'TRACKID1' => 'https://localhost:8080/index.php/user/TRACKID1',
 
'TRACKID2' => 'https://localhost:8080/index.php/user/TRACKID2',
 
'TRACKID3' => 'https://localhost:8080/index.php/user/TRACKID3',
 
'TRACKID4' => 'https://localhost:8080/index.php/user/TRACKID4',
 
'TRACKID5' => 'https://localhost:8080/index.php/user/TRACKID5',
)


# in frontend you can output data like:

foreach ($urls as $track_id => $url) {
    echo 'Track ID: '.track_id.' with URL: '.$url;

Reply
#9

PHP Code:
// change this
echo 'Track ID: '.track_id.' with URL: '.$url;

// to this
echo 'Track ID: '.$track_id.' with URL: '.$url
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB