viewwampkohanakohana-orm

Model and View issues on new install of Kohana 3.3.2 from newbie


Im new to Kohana and am having the following issues on day 1:

Im using Kohana 3.3.2 with wampServer and I can get to the Hello World at localhost with no issues.

I have the Kohana install in the root of my www directory, so I set my base url in bootstrap.php as so:

 Kohana::init(array(
    'base_url'   => '/',
   ));

As I said, "hello world" loads fine at localhost

I turned on ORM and Database in the bootstrap as well

I made a file called User.php and saved it in application/classes/Model/User.php

Inside that I have:

   class Model_User extends ORM

    {

    }

As copied from a tutorial on the web

So appending to the welcome controller, under the output statement that creates hello world, i have:

$user = ORM::factory("User");

and I get the error:

ErrorException [ Fatal Error ]: Class 'Model_User' not found
MODPATH\orm\classes\Kohana\ORM.php [ 46 ]

I know from looking around this page should be familiar to you all, and I saw all the stuff about it not being the right case and the underscores as path (ie Model_User is really Model/User) and I have checked all my cases and paths. Cant figure out whats going wrong

So I said, let me try and do a view, so I made application/views/myview.php

its got a standard html page in there with a couple of tags <p>If you see me, the view loaded.</p>

I went back into the welcome controller and commented out the above ORM::factory line (so it again just showed hello world) and added from another tutorial on views:

 $this->request->response = View::factory( 'myview' );

and I get nothing but Hello World.

I think something must be wrong with my paths but I cant figure out what, Im hoping you guys can help.

Note: there is no .htaccess in play here as this is running locally and in fact I only just put wamp on this machine yesterday for testing kohana, so it should be just a clean fresh install.

Any words of wisdom Kohana gurus? Much appreciated!

EDIT: here is the source of the welcome controller:

class Controller_Welcome extends Controller {

    public function action_index()
    {
        $this->response->body('hello, world!');



            $this->request->response = View::factory( 'myview' );

        //$user = ORM::factory("user");
     }
}

as described above, If I uncomment the ORM line, I get the error page, calling the view, i just get hello world.


Solution

  • You are using default kohana files so just change this line:

    $this->request->response = View::factory( 'myview' );
    

    to:

    $this->response->body(View::factory( 'myview' ));
    

    And your view will render correctly.

    Your model looks correct and it should work, it is working for me... Check if you don't forgot about

    <?php  ?> 
    

    tags in model.

    Check also if you have enabled mod_rewrite in server settings. Probably it will throw 404 error if disabled but it is worth to check...