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?

4

4 回答 4

1

当然,问题在于文件夹和文件名。

来自 Kohana v3.3 文档:“类名的首字母应为大写字母,并带有下划线来分隔单词。下划线很重要,因为它们直接反映了文件系统中的文件位置。”

classes/view/user.php 应该变成 classes/View/User.php

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

于 2014-07-08T19:14:00.143 回答
0

Views 文件夹不应该在类下,但应该是这样的:

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

您可以在这里查看http://kohanaframework.org/3.0/guide/kohana/files以供参考。

于 2013-04-27T16:38:33.817 回答
0

事实证明,这是我的文件夹和文件名的案例问题。

classes/view/user.php 应该是

classes/View/User.php 用于我命名为 View_User 的类

更改此设置后,一切都按预期工作。

于 2013-04-27T20:03:25.403 回答
0

您可能有权限问题。就我而言,是 httpd 服务 (apache2) 无法访问我的网络项目文件。这是一个残酷的解决方案(只有在您的安全情况允许时才这样做):

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

更多信息: move_uploaded_file 在我完成所有配置后给出“无法打开流:权限被拒绝”错误

于 2017-09-12T13:45:18.547 回答