i create a custom Observer :

class Observer_Test extends Orm\Observer 
{    
    public function after_insert(Orm\Model $model)
    {
        \Log::info('Succesfully created new object of class '.get_class($model));
    }
}

i put this code in app/classes/observer/test.php

and i called from my model in app/classes/model/ this my observer

protected static $_observers = array(
     'Observer\Observer_Test' => array(
           'events' => array('after_insert'),
     ),            
); 

and i got an error message like this

ErrorException [ Error ]: Uncaught exception 'Fuel\Core\FuelException' with message 'Unable to create or write to the log file. Please check the permissions on /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/app/logs/' in /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/log.php:77 Stack trace: #0 [internal function]: Fuel\Core\Log::_init() #1 /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/autoloader.php(364): call_user_func('Log::_init') #2 /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/autoloader.php(247): Fuel\Core\Autoloader::init_class('Log') #3 [internal function]: Fuel\Core\Autoloader::load('Log') #4 /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/base.php(91): spl_autoload_call('Log') #5 /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/error.php(117): logger(400, 'Error - Observe...') #6 /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/bootstrap.php(71): Fuel\Core\Error::exception_handler(Object(UnexpectedValueException))

i think i wrong when i called or put the observer, what is the best practices for creating an observer?

有帮助吗?

解决方案

as I see, the error says that there is not enough permission to write to that directory, and observer itself is working. to make sure, just replace Log::() call with something like die('WORKS!'); instead.

To fix the problem, so the logs would start writing, try to fix the directory permissions. I'm not sure how MacOSX handles this but this might heenter code herelp you:

cd /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER

find . -type f -exec chmod 666 {} \;
find . -type d -exec chmod 777 {} \;

1st command will cd to you web project 2nd will make all files in that directory to chmod to 666 (read/write by everyone) 3rd command will make read/write/execute by everyone

Hope that helps Good luck :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top