(12-20-2019, 06:57 AM)MGatner Wrote: Edit (or create) your .env file and set the environment to “development” - that will show you the actual error instead of the generic “Whoops”
I get "Argument 1 passed to url_title() must be of the type string, null given, called in C:\xampp\htdocs\ci4\app\Controllers\News.php on line 49".
I think I must look for a POST before I run $model->save(). So I update my news/create() to:
PHP Code:
<?php namespace App\Controllers;
use App\Models\NewsModel;
use CodeIgniter\Controller;
class News extends Controller
{
public function create()
{
helper('form');
$model = new NewsModel();
if (!$_POST OR $model->save([
'title' => $this->request->getVar('title'),
'slug' => url_title($this->request->getVar('title')),
'body' => $this->request->getVar('body'),
]) === false)
{
echo view('templates/header', ['title' => 'Create a news item']);
echo view('news/create', ['errors' => $model->errors()]);
echo view('templates/footer');
}
else
{
echo view('news/success');
}
}
}
Now I can insert new posts but if I submit an empty form, my validation error doesn't display. My view:
PHP Code:
<h2><?= esc($title); ?></h2>
<?= \Config\Services::validation()->listErrors(); ?>
<form action="/news/create" method="post">
<label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="body">Text</label>
<textarea name="body"></textarea><br />
<input type="submit" name="submit" value="Create news item" />
</form>
d in C:\xampp\htdocs\ci4\app\Controllers\News.php on line 49ng, null given, called in C:\xampp\htdocs\ci4\app\Controllers\News.php on line 49