Problema CodeIgniter

Salut,

Lucrez la un blog in CodeIgniter. Am adaugat un controller pentru posturi cu metoda “create”.
Problema e ca atunci cand incerc sa intru pe /blog/create primesc eroarea asta:

Controllerul arata asa:

<?php namespace App\Controllers;

use  App\Models\BlogModel;

class Blog extends BaseController {

    function post($slug) {

        echo view('templates/header');
        echo view('blog/post');
        echo view('templates/footer');

    }

        function create() {
            helper('form');
            $model = new BlogModel();

            if(! $this->validate([
                'title' => 'required | min_length[3] | max_length[255]',
                'body' => 'required'
            ])) {
                echo view('templates/header');
                echo view('blog/post');
                echo view('templates/footer');
            } else {
                $model->save(
                    [
                        'title' => $this->request->getVar('title'),
                        'body' => $this->request->getVar('body'),
                        'slug' => url_title($this->request->getVar('title'))
                    ]
                );
            
                return redirect()->to('/');
            }
        }
	//--------------------------------------------------------------------

}

Controllerul l-am scris dupa un tutorial in care la el vad ca merge…aveti vreo idee ce ar insemna eroarea respectiva?

Nu cred ca le-am vazut scrise vreodata cu spatiu, normal daca e bine implementat ar trebui sa mearga… dar… incearca sa scrii asa:

2 Likes

multumesc mult, a mers. pace

1 Like

Poti sa imi spui ce face | te rog?
Nu am gasit…


Citeste in documentatie ca ai tot acolo

In particular pt ce ai tu

Cascading Rules

CodeIgniter lets you pipe multiple rules together. Let’s try it. Change your rules in the third parameter of rule setting method, like this:

$this->form_validation->set_rules(
        'username', 'Username',
        'required|min_length[5]|max_length[12]|is_unique[users.username]',
        array(
                'required'      => 'You have not provided %s.',
                'is_unique'     => 'This %s already exists.'
        )
);
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');

The above code sets the following rules:

  1. The username field be no shorter than 5 characters and no longer than 12.
  2. The password field must match the password confirmation field.
  3. The email field must contain a valid email address.
4 Likes

Tocmai ma pregateam sa raspund :slight_smile:

Thank yoooou