File: tests/SimpleController.php

Recommend this page to a friend!
  Classes of Maik Greubel  >  Caribu MVC  >  tests/SimpleController.php  >  Download  
File: tests/SimpleController.php
Role: Example script
Content type: text/plain
Description: Class source
Class: Caribu MVC
MVC framework with controllers using annotations
Author: By
Last change:
Date: 4 years ago
Size: 1,973 bytes
 

Contents

Class file image Download
<?php
namespace Nkey\Caribu\Mvc\Tests;

use \
Nkey\Caribu\Mvc\Controller\AbstractController;
use \
Nkey\Caribu\Mvc\Controller\Request;

/**
 * A simple test controller
 *
 * @author Maik Greubel <greubel@nkey.de>
 *
 * This file is part of Caribu MVC package
 */
class SimpleController extends AbstractController
{

   
/**
     * @webMethod
     *
     * @title Hey there page
     */
   
public function index()
    {
        echo
"Hey, there!\n\n";
    }

   
/**
     * @responseType text/plain
     *
     * @param \Nkey\Caribu\Mvc\Controller\Request $request
     */
   
public function paramTest(Request $request)
    {
        foreach (
$request->getParams() as $param => $value) {
           
printf("%s => %s\n", $param, $value);
        }
    }

    public function
formTest(Request $request)
    {
        if(
$request->getParam("loggedin", 'boolean')) {
           
printf('<a href="%ssimple/logout">logout</a>', $request->getContextPrefix());
        } else {
           
$this->viewParams['form']['login'] = array(
               
"controller" => "simple",
               
"action" => "login",
               
"fields" => array(
                    array(
"name" => "username"),
                    array(
"name" => "password", "type" => "password")
                ),
               
"buttons" => array(
                    array(
"name" => "Login")
                )
            );

            echo
"{form=login}";
        }
    }

    public function
login(Request $request)
    {
        if(
$request->getParam("username") == "test" && $request->getParam("password") == "tset") {
           
$_SESSION['loggedin'] = true;
        }
       
$this->response->addHeader('Location', sprintf('%ssimple/formTest', $request->getContextPrefix()));
    }

    public function
logout(Request $request)
    {
        unset(
$_SESSION["loggedin"]);
       
$this->response->addHeader('Location', sprintf('%ssimple/formTest', $request->getContextPrefix()));
    }
}


For more information send a message to info at phpclasses dot org.