0

I am stumped, I must be missing something basic, any ideas would be much appreciated.

I have setup a new Kohana project which works fine with Models and Controllers. For this example I have stripped it right back to a single very basic Model for a User and a single Controller with a single index action inside it.

I decided to use KOstache as my template engine as I heard good things about it. I downloaded the module and the vendor submodule and this does seem to work fine.

My problem arrises when trying to create a new instance of my view model class named View_User, kohana throws an * ErrorException [ Fatal Error ]: Class 'View_User' not found *

My directory structure is as follows

application
   |_classes
   |     |_Controller
   |     |   |_User.php
   |     |_Model
   |     |   |_User.php
   |     |_view
   |         |_user.php
   |_templates
         |_user.mustache

There are other folders within the project but I believe these are the relevan ones.

My controller seems to be the class with the problem

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_User extends Controller {

        public function action_index()
        {
                $renderer = Kostache_Layout::factory();
                $view = new View_User;
                $view->title = 'This is the test title';
                $this->response->body($renderer->render($view));
        }

}

This does not work and complains that it cannot find class View_User yet in my classes/view/user.php file I clearly have a View_User class

<?php
class View_User {
}

Now I assume it is some sort of problem with the way I am setting up KOstache or Kohana, but I am unsure what I am doing wrong.

If I include the class definition at the bottom of the classes/Controller/User.php then everything works as expected, it just doesn't find the class within another file.

From what I've read if the autoloader tries to load class View_User it will look in classes/view/user.php

What am I doing wrong?

Jon Taylor
  • 7,865
  • 5
  • 30
  • 55
  • What Kohana version are you using? I noticed you tagged it 3.2 but I can see why it wouldn't work if it was 3.3. – Michal M Apr 27 '13 at 21:19
  • @MichalM Sorry, the tag was wrong, I am using 3.3. It was a directory naming problem it needed to be classes/View/User.php not classes/view/user.php since the class name was View_User not view_user. – Jon Taylor Apr 27 '13 at 21:37
  • That's what I thought, hence the question. :) – Michal M Apr 28 '13 at 16:39

4 Answers4

1

Sure, the issue its with Folders and File names.

From Kohana v3.3 Doc: "Class names should have uppercase first letters with underscores to separate words. Underscores are significant as they directly reflect the file location in the filesystem."

classes/view/user.php should become classes/View/User.php

Reference: http://kohanaframework.org/3.3/guide/kohana/conventions#class-names-and-file-location

Quincy Kwende
  • 76
  • 2
  • 5
0

Views folder shouldn't be under classes, but should be like this:

application
 |_classes
 |     |_Controller
 |     |   |_User.php
 |     |_Model
 |     |   |_User.php
 |_views
 |  |_user.php
 |_templates
    |_user.mustache

You can look here http://kohanaframework.org/3.0/guide/kohana/files for reference.

dave
  • 62,300
  • 5
  • 72
  • 93
  • I believe this is true for Kohana views but not View_Models for KOstache. Either way I have tried putting it in the views folder and this still has the same exception thrown. – Jon Taylor Apr 27 '13 at 16:40
0

It turns out that it was a case issue on my folders and filenames.

The classes/view/user.php should have been

classes/View/User.php for classes I named View_User

After changing this it all works as expected.

Jon Taylor
  • 7,865
  • 5
  • 30
  • 55
0

You might have a permission problem. In my case it was the httpd service (apache2) that couldn't access my web-project files. Here is a brutal solution (do it only if your security situation allows it):

$ sudo chmod -R 0777 /var/www/html/mysite/

More info: move_uploaded_file gives "failed to open stream: Permission denied " error after all configurations i did

Machavity
  • 30,841
  • 27
  • 92
  • 100
Antonello
  • 11
  • 1
  • 1
    `chmod 777` is generally a [terrible solution](https://serverfault.com/questions/364677/why-is-chmod-r-777-destructive) – Machavity Sep 12 '17 at 13:52