How to get special element of object

Hi guys,

I tried to get filename of a picture -which is deposited in database- coding like this:





    [

.

.

.


            'value' => function($model) {   		

            $vorname = Person::findOne([$model->id_person])->vorname;

            $nachname = Person::findOne([$model->id_person])->nachname;

            $matchcode = $vorname . "," . $nachname;

            $bilder =LBild::findOne(['matchcode' => $matchcode]);

.

.

.



I noticed,that,


 	$ausgabe = array($bilder->dateiname);

            var_dump($ausgabe);

shows up this:




array(1) {  [0]=>  string(28) "Passbild_Moi_Black_White.jpg"}array(1) {  [0]=>  string(16) "moi_large_sw.jpg"} 



These are filenames of pictures,which I have in database and in folder frontend/web/pictures

I only need one of this filenames,not both.

So, I started complementing code like this, but I didn’t succeed…




$x = 0;

$pictures = array();

foreach ($bilder as $key => $val) {

	$pictures[$x] = $bilder->dateiname;

        $x++;

}

$output = array_slice($pictures, -14, 1);



var_dump() will show this, now:




array(1) {  [0]=>  string(28) "Passbild_Moi_Black_White.jpg"}array(1) {  [0]=>  string(16) "moi_large_sw.jpg"} 



Any ideas, how to achieve,that var_dump() only will show up one single value,for instance like this:




string(28) "Passbild_Moi_Black_White.jpg"



It would be best, If I got an array like this:




array(2) {  [0]=>  string(28) "Passbild_Moi_Black_White.jpg" 

 [1]=> string(16) "moi_large_sw.jpg"

}



I know each framework has their little things / ways to do things. But I usually just stick with the "php way" for a lot of things. Here is a delete function where I am also deleting the associated file. This works in laravel, cake, yii, etc.




    function delete()

    {

        if ($this->chklog() == 'notlogged') {

            Url::redirect('admin');

        }

        $id = $_GET['id'];

        $this->Dog->delete($id);

        $dfile = "NO File";

        if (!empty($_GET['tmppic'])) {

            $tmppic = $_GET['tmppic'];

            $target_path = ROOT . 'upload/imgdogs/';

            $tmpfile = $target_path . $tmppic;


            if (is_file($tmpfile)) {

                if (!unlink($tmpfile)) {

                    $dfile = "Error deleting file";

                } else {

                    $dfile = "File deleted";

                }

            }

        }

        $data["msg"] = $dfile;

        $path = 'dog/imgdel';

        View::render($path, $data);

        

    }



The example is not from yii2, but will work with correct adjustments.

I pass the name along like:


<td><a href="<?php echo DIR . 'dog/delete?id=' . $row->dogid . '&tmppic=' . $row->dogpic; ?>" class="delete">Delete</a></td>

I absolutely don’t recognize, how ur code could solve my problem. I don’t want to delete anything, I want to extract informations of object as explained above.

I noticed for longer, that U answer my posts with comments, which have nothing to do with question. So, I seek U politely: Don’t comment my post(s) in future, any more.

Thx for ur understanding…

I got solution. Now, picture will be shown up as desired.

My solution is like this,which will give me name of each filename directly:





    public static function getBild($matchcode) {

        try {

            return LBild::find()->where(['matchcode' => $matchcode])->all();

        } catch (\Exception $e) {

            return true;

        }

    }



I will extract filenames like this:




.

.

.

'value' => function($model) {   

            $pics="";   

            $vorname = Person::findOne([$model->id_person])->vorname;

            $nachname = Person::findOne([$model->id_person])->nachname;

            $matchcode = $vorname . "," . $nachname;

            $bilder = LBild::getBild($matchcode);          

            foreach($bilder as $bild){

            $pics=$bild->dateiname;

            }  

.

.

.

return 		

            $pic = Html::img("@web/pictures/".$pics, ['alt' => 'pic not found', 'style' => 'width:50px; height: 50px']);

 }