Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $input['user_id'] = Sentry::getUser()->id;
     // die("UserID = ".Sentry::getUser()->id);
     $validation = Validator::make($input, Todo::$rules);
     if ($validation->passes()) {
         $this->todo->create($input);
         return Redirect::route('user.todos.index');
     }
     return Redirect::route('user.todos.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }
 /**
  * レコード追加
  */
 public function add()
 {
     // 値一覧のセット
     $this->set('valueLists', $this->Todo->valueLists);
     if (!empty($this->data)) {
         // POST時
         $this->Todo->create();
         if ($this->Todo->save($this->data)) {
             $this->Session->setFlash(__('TODOを追加しました', true));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('TODOの追加に失敗しました', true));
         }
     }
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Todo::create([]);
     }
 }
 /**
  * Store a newly created todo in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Todo::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     Todo::create($data);
     return Redirect::route('todos.index');
 }
 public function run()
 {
     DB::table('todos')->truncate();
     foreach (Organization::all() as $org) {
         Todo::create(['name' => 'First Todo', 'user_id' => $org->users[0]->id, 'organization_id' => $org->id, 'completed' => true]);
         Todo::create(['name' => 'Second Todo', 'user_id' => $org->users[0]->id, 'organization_id' => $org->id]);
         Todo::create(['name' => 'Todo from Second', 'user_id' => $org->users[1]->id, 'organization_id' => $org->id]);
         Todo::create(['name' => 'Third Todo', 'user_id' => $org->users[0]->id, 'organization_id' => $org->id]);
     }
 }
Esempio n. 6
0
 public function store()
 {
     $rules = ['title' => 'required|min:3|max:255'];
     $input = Input::only(['title']);
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::route('todos.index')->withErrors($validator)->withInput();
     }
     $todo = Todo::create(['title' => $input['title'], 'status' => Todo::STATUS_INCOMPLETE]);
     return Redirect::route('todos.index');
 }
 /**
  * 新規Todoを追加する。
  *
  * @return void
  */
 public function store()
 {
     // バリデーションルールの定義
     $rules = ['title' => 'required|min:3|max:255'];
     // フォームの入力データを項目名を指定して取得する
     $input = Input::only(['title']);
     // バリデーターを生成する
     $validator = Validator::make($input, $rules);
     // バリデーションを行う
     if ($validator->fails()) {
         // バリデーションに失敗したら、バリデーションのエラー情報とフォームの入力値を追加してリストページにリダイレクトする。
         return Redirect::route('todos.index')->withErrors($validator)->withInput();
     }
     // Todoデータを作成する(SQL発行)
     $todo = Todo::create(['title' => $input['title'], 'status' => Todo::STATUS_INCOMPLETE]);
     // リストページにリダイレクトする
     return Redirect::route('todos.index');
 }
Esempio n. 8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $todo = Todo::create(Request::all());
     return $todo;
 }
Esempio n. 9
0
<?php

require_once "api/database.php";
require_once "api/todo.php";
$todo = new Todo();
switch ($_SERVER['REQUEST_METHOD']) {
    case 'GET':
        $params = str_replace('/', '', $_SERVER['QUERY_STRING']);
        parse_str($params, $params);
        $todo->read($params);
        break;
    case 'PUT':
        parse_str(file_get_contents('php://input'), $p_data);
        $object = json_decode(stripslashes($p_data['model']), true);
        $todo->update($object);
        break;
    case 'POST':
        $object = json_decode(stripslashes($_POST['model']), true);
        $todo->create($object);
        break;
    case 'DELETE':
        $id = (int) str_replace('/', '', $_SERVER['QUERY_STRING']);
        $todo->delete($id);
        break;
}
Esempio n. 10
0
        return json_encode($todo);
    }
    return $app->redirect('/todo');
})->value('id', null);
$app->post('/todo/add', function (Request $request) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    $user_id = (int) $user['id'];
    $description = $request->get('description');
    // if is empty description send back to todo and display error
    if (!$description) {
        return $app->redirect('/todo?empty_description=true');
    }
    $todo = new Todo($app);
    $operation_status = $todo->create(['user_id' => $user_id, 'description' => $description]);
    if ($operation_status) {
        $app['session']->getFlashBag()->add('success_confirmation', 'Successfully added todo');
    }
    return $app->redirect('/todo');
});
$app->post('/todo/update/{id}', function (Request $request, $id) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    if ($id) {
        $int_id = (int) $id;
        $completed = $request->request->get('completed');
        if ($completed === 'c') {
            // Make sure we added user_id to query so users can only change their own
            $sql = 'UPDATE todos SET status = "c" WHERE id = ? AND user_id = ?';
Esempio n. 11
0
?>

<?php 
//refresh page to reflect new changes
function refresh()
{
    header("Location: .");
}
//submit/update an item
if (isset($_POST) && isset($_POST['title'])) {
    if ($_POST['title']) {
        $title = strip_tags(stripslashes($_POST['title']));
        if (isset($_POST['id'])) {
            Todo::update($_POST['id'], $title);
        } else {
            Todo::create($title);
        }
    }
    refresh();
}
//delete an item
if (isset($_GET['delete']) && isset($_GET['id'])) {
    if (filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
        Todo::delete($_GET['id']);
        refresh();
    }
}
//view a single item
if (isset($_GET['id'])) {
    $id = stripslashes(strip_tags($_GET['id']));
    if (filter_var($id, FILTER_VALIDATE_INT)) {