Skip to content

Add function for handling json responses #57

@jrgmartin

Description

@jrgmartin

Should live in the template controller?

/**
     * Takes the given parameters and returns a formed JSON string
     * @param string $state success/error
     * @param mixed $data the data to be returned
     * @param string $layout the HTML to be returned
     * @param null|array $errors
     * @param null|array $extra any additional array pairs to return
     * @param string $type
     */
    public function response($state, $data, $layout = null, $errors = null, $extra = null, $type = 'json') {

        if($type == 'json') {

            $json = array(
                'state' => $state,
                'data' => $data,
                'layout' => $layout,
                'errors' => $errors
            );

            if($extra) $json = array_merge($json, $extra);

            echo json_encode($json);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions