doxd96148 2013-04-27 16:22
浏览 28
已采纳

Kohana查看模型类未找到

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条回答 默认 最新

  • dongnai6973 2014-07-08 19:14
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题