Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Strange error with get_one()
  • Hi all,
    I have a strange behavior with an application I'm coding right now (a simple blog) with fulephp v1.2.1. I've created an action for the entries of the blog, so when user enters an url like that:
    http://www.mysite.com/blog/2012/08/17/my-first-blog ... i use the slug "my-first-blog" to find the content in the database. The strange behavior is with this code, that I use to get the Content Model:
    $content = Model_Content::find()->where('slug', $slug)->get_one();
    $this->template->subtitle = $content->title;
    

    The application works very well: all operations are done and the view is correctly loaded, but every time I call this page fule generates an error log in the log folder like this: Error - 2012-08-17 22:13:14 --> 8 - Trying to get property of non-object in C:\Users\ilNotturno\Workspace\progetti\blog\application\app\classes\controller\public\blog.php on line 49 All values are ok (I've log them with the Log class of Fuel's Core), so I can't understand the problem. Just to be exaustive: if try to get the same content with this code:
    $content = Model_Content::find(1);
    

    all goes well and o logs are generated. Might it be a bug with "get_one" function? The exists another way to do that?
  • find(1) runs a get_one() too, so I don't think this is the issue. Do you still get the error if you do this instead:
    $content = Model_Content::find()->where('slug', $slug)->get_one(); 
    $this->template->set('subtitle', $content->title);
    
  • I think I've found the error, but I can't understand it.
    I have this code: Routing rule
    'blog/(:num)/(:num)/(:num)/(:any)'  => 'public/blog/content/$4',
    

    Action in Blog Controller
    public function action_content($slug) 
        {
            Log::error('SLUG: ' . $slug);
            $content = Model_Content::find()->where('slug', 'goal-for-2012')->get_one(); 
            
            $this->template->set('subtitle', $content->title);
            (... MORE ...)
    

    I've insert a Log so I can see the value of "$slug". THis is what I found in my error log: Error - 2012-08-18 14:51:58 --> SLUG: goal-for-2012
    Error - 2012-08-18 14:51:59 --> SLUG: style
    Error - 2012-08-18 14:51:59 --> SLUG: style
    Error - 2012-08-18 14:51:59 --> SLUG: style
    Error - 2012-08-18 14:51:59 --> SLUG: style
    Error - 2012-08-18 14:51:59 --> SLUG: style The first one is my slug: I have an url like http://127.0.0.1/mysite/blog/2012/8/17/goal-for-2012 so it is correct... But what the hell are the line with "SLUG: style"? How call them and is it possible? So ORM works perfectly indeed...
  • Find out the problem. I'll insert here the problem and the solution. The problem was that, converting a template to work with FuelPHP, I leave in the code some images with an absolute url, like /mysite/blog/style/img1.png.
    I use mod_rewrite and I have putted the index in the root, so every time an image was asked to the server, it called the bog controller, writing the errors. The solution was to create images using the asset class. Thanks for your time and sorry for this stupid error :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion