Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Using Array Data In A View

$
0
0
Hello,

Being quite new to yii and the MVC approach, I'm still in the "what goes where?" phase, and so I'm sorry in advance if what I ask seems obvious.

I'm trying to build a basic requirement page (php version, $_SERVER etc), so I wrote an utilitary class used in one of my controller action:

class DefaultController extends Controller
{
    public function actionRequirements()
    {
        $servicesData = ServicesUtil::checkServices();
        $this->render('requirements', array('servicesData' => $servicesData));
    }
}


$servicesData looks like:

Array
(
    [1] => Array <-- Requirement is met
        (
            [0] => Array
                (
                    [service] => PHP
                    [message] => PHP version ok (5.4.3).
                )
            [1] => Array
                (
                    [service] => ServerVariable
                    [message] => $_SERVER is accessible.
                )
        )
    [2] => Array <-- Requirement is not met
        (
            [1] => Array <-- Service required
                (
                    [0] => Array
                        (
                             [service] => Curl
                             [message} => Curl extension is not loaded.
                        )
                )
            [2] => Array <-- Service optional
                (
                )
        )
)


And my view "requirements" looks like:

if (count($servicesData[2]) > 0)
{
    if (count($servicesData[2][1]) > 0)
    {
        foreach($servicesData[2][1] as $failedRequiredService)
        {
            echo $failedRequiredService['message'];
        }
        echo '<br/><br/>';
    }
    if (count($servicesData[2][2]) > 0)
    {
        foreach($servicesData[2][2] as $failedOptionalService)
        {
            echo $failedOptionalService['message'];
        }
        echo '<br/><br/>';
    }
}
if (count($servicesData[1]) > 0)
{
    foreach($servicesData[1] as $passedService)
    {
        echo $passedService['message'];
    }
}


From what I understand, there should be far less logic in my view. So is there someone who could explain to me how to properly write this view ?

Many thanks for considering my request

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>