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 :)
Related
Clojure: 1.10.0
clojurescript: "1.10.764
shadow-cljs "2.11.7"
re-frame "1.2.0"
I am creating a SPA using re-frame, and everything is working well. However, I recently watched a video on o'Doyle rules engine and I thought it might be fun to try experimenting with this in my re-frame project. It creates a separate "facts table" in its own atom:
(ns cube-test.twizzlers.rules
(:require
[re-frame.core :as re-frame]
[odoyle.rules :as o]))
(def rules
(o/ruleset
{::print-time
[:what
[::time ::total tt]
:then
(println "upate time rule:" tt)]}))
;; create session and add rule
(def ^:dynamic *session
(atom (reduce o/add-rule (o/->session) rules)))
(defn update-time []
(swap! *session
(fn [session]
(-> session
(o/insert ::time ::total 100)
o/fire-rules))))
I then created a button to activate the update:
[:button.user-action {:on-click #(re-frame/dispatch [::twiz.events/update-time])} "update time rule"]
The rule fires and everything works well, however I see a bunch of re-frame warnings on the console suggesting that re-frame is trying to hook and manage the Odoyle atom as one of it's own:
"twizzler.events.update-time: entered" cljs.core.js:168:20
upate time rule: 100 cljs.core.js:168:20
re-frame: no handler registered for effect:
Object { ns: null, name: "alpha-node", fqn: "alpha-node", _hash: 1411603897, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "beta-nodes", fqn: "beta-nodes", _hash: -674152665, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "last-id", fqn: "last-id", _hash: -1231616450, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "rule-name->node-id", fqn: "rule-name->node-id", _hash: -494456865, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "node-id->rule-name", fqn: "node-id->rule-name", _hash: 1615893599, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "id-attr-nodes", fqn: "id-attr-nodes", _hash: -1814751183, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "then-queue", fqn: "then-queue", _hash: 899186975, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
re-frame: no handler registered for effect:
Object { ns: null, name: "then-finally-queue", fqn: "then-finally-queue", _hash: 2088468149, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096 }
. Ignoring. cljs.core.js:13285:10
"then-finally-queue" and "alpha-node" et. al are presumably o'doyle life cycle events on it's atom, and it looks like re-frame is trying to find handlers for them.
This question isn't really about making odoyle rule engine and re-frame work together, although if anyone has opinions about the plausibility of this scenario I'd be interested in hearing them (yes, there's an overlap between the frameworks, but I would regard the odoyle "fact table" as simply an alternate view that I would manage with re-frame subscriptions).
Anyhow, to make it clearer that this question isn't simply about odoyle, or an effect of odoyle's design, I created a generic atom like so:
(def ^:dynamic *a* (atom 10))
(defn update-atom []
(swap! *a* inc))
and when I drive it, it generates:
"twizzler.events.update-dmy-atom: entered" cljs.core.js:168:20
Uncaught Error: No protocol method IMap.-dissoc defined for type number: 12
cljs$core$missing_protocol https://localhost:8281/js/compiled/cljs-runtime/cljs.core.js:312
cljs$core$IMap$_dissoc$dyn_41386 https://localhost:8281/js/compiled/cljs-runtime/cljs.core.js:2213
cljs$core$_dissoc https://localhost:8281/js/compiled/cljs-runtime/cljs.core.js:2224
cljs$core$IFn$_invoke$arity$2 https://localhost:8281/js/compiled/cljs-runtime/cljs.core.js:6832
re_frame$fx$do_fx_after https://localhost:8281/js/compiled/cljs-runtime/re_frame.fx.js:40
re_frame$interceptor$invoke_interceptor_fn https://localhost:8281/js/compiled/cljs-runtime/re_frame.interceptor.js:216
re_frame$interceptor$invoke_interceptors https://localhost:8281/js/compiled/cljs-runtime/re_frame.interceptor.js:255
re_frame$interceptor$execute https://localhost:8281/js/compiled/cljs-runtime/re_frame.interceptor.js:365
re_frame$events$handle https://localhost:8281/js/compiled/cljs-runtime/re_frame.events.js:85
re_frame$router$IEventQueue$_process_1st_event_in_queue$arity$1 https://localhost:8281/js/compiled/cljs-runtime/re_frame.router.js:580
re_frame$router$IEventQueue$_run_queue$arity$1 https://localhost:8281/js/compiled/cljs-runtime/re_frame.router.js:325
vec__42331 https://localhost:8281/js/compiled/cljs-runtime/re_frame.router.js:417
re_frame$router$IEventQueue$_fsm_trigger$arity$3 https://localhost:8281/js/compiled/cljs-runtime/re_frame.router.js:459
G__42328 https://localhost:8281/js/compiled/cljs-runtime/re_frame.router.js:370
NextJS 3
day8$re_frame_10x$inlined_deps$re_frame$v0v12v0$re_frame$router$IEventQueue$_run_next_tick$arity$1 https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.inlined_deps.re_frame.v0v12v0.re_frame.router.js:372
vec__42751 https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.inlined_deps.re_frame.v0v12v0.re_frame.router.js:478
day8$re_frame_10x$inlined_deps$re_frame$v0v12v0$re_frame$router$IEventQueue$_fsm_trigger$arity$3 https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.inlined_deps.re_frame.v0v12v0.re_frame.router.js:549
day8$re_frame_10x$inlined_deps$re_frame$v0v12v0$re_frame$router$IEventQueue$push$arity$2 https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.inlined_deps.re_frame.v0v12v0.re_frame.router.js:363
day8$re_frame_10x$inlined_deps$re_frame$v0v12v0$re_frame$router$dispatch https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.inlined_deps.re_frame.v0v12v0.re_frame.router.js:699
day8$re_frame_10x$db$init_db https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.db.js:24
day8$re_frame_10x$init_db_BANG_ https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.js:352
<anonymous> https://localhost:8281/js/compiled/cljs-runtime/day8.re_frame_10x.preload.js:3
globalEval https://localhost:8281/js/compiled/app.js:597
evalLoad https://localhost:8281/js/compiled/app.js:1690
<anonymous> https://localhost:8281/js/compiled/app.js:2162
app.js line 597 > eval:312:9
IOTW, re-frame is trying to "manage" this atom as well.
It looks like re-frame hooks all atom processing functions not just its own app-db ratom?
Is there a way I can mark an atom to exclude it from re-frame's hooks? Or will I be forced to create a non-re-frame project to experiment with odoyle? Note: odoyle has an adapter for Rum, so it can work with other reactive frameworks.
Regarding the superfluous messages:
This is an "answer" from the original poster. Since I received no responses, I'll just explain what I discovered and how I dealt with the situation. I do not claim to have any expert knowledge of re-frame beyond what I know as a basic user of the framework.
In looking at the source code for re-frame (which is amazingly quite small, and not very complicated BTW), fx.cljs seems to be the source of all the messages I see. I can see that in fact it has a lot of interceptors:
(def do-fx
(->interceptor
:id :do-fx
:after (fn do-fx-after
After thinking about it, it makes sense that the hooking and intercepting is tied to the code and not to the atom i.e. you typically have one copy of the code loaded to deal with n atoms.
My main concerns about re-frame hooking my non-reframe atoms are twofold: performance and interference. As far as performance goes, this is just re-frame doing a simple check for a handler, not finding it, and printing a warning message. Since state changes are at app level and not on the animation tick (my project is a Babylon.js 3d app), this is not a big issue. Indeed, to add a lookup table of what atoms to monitor or not, while also not a big performance hit, would, if anything, decrease the performance even further. So no big deal to have these messages.
I also realize that re-frame should not be interfering with the non-reframe atom at all. Indeed, these messages are an indication that re-frame is unable to intercept the native atom. So once again nothing to worry about.
So I was able to convince myself that these messages are really nothing to worry about. However, the specter of having a lot of superfluous wordy message clogging up my console was annoying.
To deal with getting rid of all the messages, I made a call to re-frame's set-loggers! call, where I used a regex to filter the superfluous messages, something like:
(defn rf-odoyle-warn-override-logger [& args]
(let [text (apply str args)]
; (prn "utils.rf-odoyle-warn-override-logger: text=" text)
(if (re-matches #".*no handler registered for effect:.*Ignoring.*" text)
(js/console.log "probable rf-odoyle interceptor no handler msg warning detected")
(js/console.warn text))))
Invoked like this in my startup:
(re-frame.core/set-loggers! {:warn utils/rf-odoyle-warn-override-logger})
Now, I just get one simple "collapsed" message in the console:
probable rf-odoyle interceptor no handler msg warning detected
On using re-frame and o'doyle together:
vis a vis the viability of using o'doyle rules in re-frame, I see great promise for me since my main "view" is a babylon.js scene and not the DOM. Thus I need to do a lot of game level logic outside of the DOM, where I think O-doyle will complement re-frame. If your app is a basic Web app where the DOM is your main view, then I think it might feel kind of redundant to attempt to maintain odoyle state on top of the re-frame state (e.g. in app.db).
Purpose
Hello, I am fairly new to Symfony and am trying to create an exception/error handling functionality for our Web API.
Requirements
When a user makes an invalid request to our API, we want to return a simple JSON object that looks something like the following:
{"errorCode": 1234567, "errorMessage": "Parameter 1 is invalid. String expected"}
In addition to API-specific errors, we also want to hook into the built-in exception-handling in Symfony and re-use that, but instead of returning an HTML error page (which is what happens by default), we want to return a JSON object like:
{"errorCode": 404, "errorMessage": "Not found"}
Current Approach
Obviously, we want this to be implemented in the most efficient way, so after doing some research, I found what I think is a great approach which I can then adapt to our specific needs. Here is the tutorial I followed:
https://knpuniversity.com/screencast/symfony-rest2
I ended up buying this course in order to get access to the full code. The issue is that it was written for Symfony 2, but we are running Symfony 3.3, so some things are outdated and I have not been able to get the example running yet.
Code
So, I have posted some of the relevant code below. (I obviously cannot post the whole code, but have posted what are hopefully the relevant portions of the publicly-available code).
services.yml (Their version, Symfony 2 Style)
api_exception_subscriber:
class: AppBundle\EventListener\ApiExceptionSubscriber
arguments: []
tags:
- { name: kernel.event_subscriber }
services.yml (my full file with all comments removed)
This includes a modified version of what they have above (hopefully this is the correct Symfony 3.3 way of doing things).
NOTE: Anything that was part of the private code which I cannot show, I have replaced with the word "something".
parameters:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
AppBundle\EventListener\ApiExceptionSubscriber:
arguments:
- ['%something.something%']
tags:
- {name: 'kernel.event_subscriber'}
routing.yml (relevant section of their file)
app_api:
resource: "#AppBundle/Controller/Api"
type: annotation
defaults:
_format: json
routing.yml (my full file) - NOTE: I had to add the "_format: json" directly to the "app" section here rather than "app_api" because in our REST API, all of our URLs are at the root level, and do NOT have to be prefixed with "api" like http://localhost/api/someMethod/someMethodParameter as in the tutorial's code
app:
resource: '#AppBundle/Controller/'
type: annotation
defaults: {_format:json}
yml_route:
path: /yml-route
defaults:
_controller: AppBundle:Default:yml
awesome_route:
path: /awesome-route/{ic}
defaults:
_controller: AppBundle:Rest:awesomeRoute
src/AppBundle/RestController.php (edited to show just the basic structure)
<?php
namespace AppBundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\HttpFoundation\Request;
class RestController extends Controller {
public function doSomething($id)
{
// Code to populate $result with data from database is here
return new JsonResponse($result);
}
// This file contains many different functions similar to doSomething() which retrieve the request for the API caller.
// For example, doSomething() can be accessed via http://localhost/app_dev.php/doSomething/123
}
src/AppBundle/Api/ApiProblem.php (edited to show just the basic structure)
namespace AppBundle\Api;
use Symfony\Component\HttpFoundation\Response;
class ApiProblem
{
// Code relevant to this class is in here
}
src/AppBundle/Api/ApiProblemException.php (edited to show just the basic structure)
<?php
namespace AppBundle\Api;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ApiProblemException extends HttpException
{
private $apiProblem;
public function __construct($severalParametersWhichICannotListHereBecauseCodeIsPrivate) {
// Does some stuff and then calls the parent:__construct
// Includes a getter for $apiProblem
}
}
src/AppBundle/EventListener/ApiExceptionSubscriber.php (edited to show just the basic structure)
<?php
namespace AppBundle\EventListener;
use AppBundle\Api\ApiProblem;
use AppBundle\Api\ApiProblemException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\KernelEvents;
class ApiExceptionSubscriber implements EventSubscriberInterface
{
// Code relevant to this subscriber is here
}
The Issue
I'm getting the following error when I try to run any type of command from the command-line bin/console:
C:\htdocs\projects\myproject>php bin/console debug:container
PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: T
here is no extension able to load the configuration for "AppBundle\EventListener\ApiExceptionSubscribe
r" (in C:\htdocs\projects\myproject\app/config\services.yml). Looked for namespace "AppBundle\EventListe
ner\ApiExceptionSubscriber", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrin
e", "sensio_framework_extra", "demontpx_parsedown", "doctrine_cache", "doctrine_migrations", "debug",
"web_profiler", "sensio_distribution", "web_server" in C:\htdocs\projects\myproject\vendor\symfony\symfo
ny\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php:644
Stack trace:
#0 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\
YamlFileLoader.php(614): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->validate(Array,
'C:\\htdocs\\proje...')
#1 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\
YamlFileLoad in C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\
FileLoader.php on line 179
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: There
is no extension able to load the configuration for "AppBundle\EventListener\ApiExceptionSubscriber" (i
n C:\htdocs\projects\myproject\app/config\services.yml). Looked for namespace "AppBundle\EventListener\A
piExceptionSubscriber", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "
sensio_framework_extra", "demontpx_parsedown", "doctrine_cache", "doctrine_migrations", "debug", "web_
profiler", "sensio_distribution", "web_server" in C:\htdocs\projects\myproject\vendor\symfony\symfony\sr
c\Symfony\Component\Config\Loader\FileLoader.php on line 179
Symfony\Component\Config\Exception\FileLoaderLoadException: There is no extension able to load the con
figuration for "AppBundle\EventListener\ApiExceptionSubscriber" (in C:\htdoc
fig\services.yml). Looked for namespace "AppBundle\EventListener\ApiExceptio
work", "security", "twig", "monolog", "swiftmailer", "doctrine", "sensio_fra
arsedown", "doctrine_cache", "doctrine_migrations", "debug", "web_profiler",
eb_server" in C:\htdocs\projects\myproject\app/config\services.yml (which is b
ocs\projects\myproject\app/config\config.yml"). in C:\htdocs\projects\myproject\
\Symfony\Component\Config\Loader\FileLoader.php on line 179
Call Stack:
1.4353 6149416 1. Symfony\Component\Debug\ErrorHandler->handleExcep
myproject\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php:
What I've Tried
I've been debugging this for the last several days and have read many related discussions on Stack Overflow. I'm fairly new to services, subscribers, and dependency injection and I've tried editing both the routes.yml and services.yml numerous times. I was also getting some circular reference exceptions before but think I've fixed those now. I was hoping someone could please provide me with some direction and hopefully help me turn this into a working example on Symfony 3.3 that I can learn from. If you need any additional detail, please let me know.
From what I've learned, autowiring/autoconfiguring of services in Symfony 3.3 seems to be new and I think that may be impacting things but I'm not sure. I did try turning both of those settings off in services.yml though but with no luck.
I have an action that prints "Hello World":
public function actionStart()
{
echo 'Hello World';
}
I will to run a cron job that calls this action every minute.
How I can do this with yiic ?
UPDATE:
I create console app. I have cron.php inside index.php:
<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once('framework/yii.php');
// we'll use a separate config file
$configFile='protected/config/c.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();
and config/c.php:
<?php
return array(
// This path may be different. You can probably get it from `config/main.php`.
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Cron',
'preload'=>array('log'),
'import'=>array(
'application.models.*',
'application.components.*',
),
// We'll log cron messages to the separate files
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron.log',
'levels'=>'error, warning',
),
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron_trace.log',
'levels'=>'trace',
),
),
),
// Your DB connection
'db'=>array(
'class'=>'CDbConnection',
// …
),
),
);
and protected/commands/MyCommand.php:
<?php
class MyCommand extends CConsoleCommand
{
public function run($args)
{
$logs = Log::model()->findAll();
print_r($logs);
die();
}
}
when I run this:
$ ./protected/yiic my
I got this error:
PHP Error[2]: include(Log.php): failed to open stream: No such file or directory
in file /path/to/app/folder/framework/YiiBase.php at line 427
#0 /path/to/app/folder/framework/YiiBase.php(427): autoload()
#1 unknown(0): autoload()
#2 /path/to/app/folder/protected/commands/MyCommand.php(6): spl_autoload_call()
#3 /path/to/app/folder/framework/console/CConsoleCommandRunner.php(71): MyCommand->run()
#4 /path/to/app/folder/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run()
#5 /path/to/app/folder/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#6 /path/to/app/folder/framework/yiic.php(33): CConsoleApplication->run()
#7 /path/to/app/folder/protected/yiic.php(7): require_once()
#8 /path/to/app/folder/protected/yiic(3): require_once()
How I can fix this?
First you have to create a command: http://www.yiiframework.com/doc/guide/1.1/en/topics.console#creating-commands
Then you can acess your function by running this command:
yiic yourCommand start
You have to load your models in Console application.
Open console.php configuration file, and add this line under the line 'name'=>'My Console Application',
'import'=>array(
'application.models.*'
),
It should work.
It seems that your don't have such 'log.php' file you are including.
maybe try this from console :
touch /path/to/app/folder/protected/log.php
You should have another error message then (or it will run smoothly).
Just open your yiic.php file check framework path in it.
After doing my code update. I got this error.
Could you help me figure this one out?
I gave 777 permission to all of the folders.
Thanks in advance!
Fatal error: Uncaught exception 'Zend_Cache_Exception' with message
'cache_dir must be a directory' in
C:\xampp\htdocs\mts\library\Zend\Cache.php:208 Stack trace: #0
C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php(154):
Zend_Cache::throwException('cache_dir must ...') #1
C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php(121):
Zend_Cache_Backend_File->setCacheDir('C:\xampp\htdocs...') #2
C:\xampp\htdocs\mts\library\Zend\Cache.php(152):
Zend_Cache_Backend_File->__construct(Array) #3
C:\xampp\htdocs\mts\library\Zend\Cache.php(93):
Zend_Cache::_makeBackend('File', Array, false, false) #4
C:\xampp\htdocs\mts\application\Bootstrap.php(22):
Zend_Cache::factory('Core', 'File', Array, Array) #5
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\BootstrapAbstract.php(636):
Bootstrap->_initCache() #6
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\BootstrapAbstract.php(589):
Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('cache') 7#
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\Boots in
C:\xampp\htdocs\mts\library\Zend\Cache.php on line 208
Setting the cache in bootstrap
protected function _initCaching() {
$frontend = array(
'lifetime' => 7200,
'automatic_serialization' => true
);
$backend = array(
'cache_dir' => sys_get_temp_dir(), /**automatically detects**/
);
$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
Zend_Registry::set('cache', $cache);
}
Go to C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php at line 154 and echo $value before the conditions. It should give you a directory address. Make sure that directory exists in your file system. Basically you need to set this path correctly in your zend configuration.
It's not about permission, ZF can't find the cache directory. Check if the directory you set in application.ini actually exists.
As you are on Windows machine, permissions shouldn't be a problem.
I get the below error when running a custom command from the yiic shell.
I am using the latest MAMP 2.0.2 on OS X 10.7.2
I am not sure what the error means by reader or member does not exist?
Line 56 is: $role->addChild("reader"); and the full code of the custom command and and terminal output is below:
users-MacBook-Air:protected user$ ./yiic shell ../index.php
Yii Interactive Tool v1.1 (based on Yii v1.1.2)
Please type 'help' for help. Type 'exit' to quit.
>> rbac
This command will create three roles: Owner, Member, and Reader and the following permissions:
create, read, update and delete user
create, read, update and delete project
create, read, update and delete issue
Would you like to continue? [Yes|No]y
exception 'CException' with message 'Either "member" or "reader" does not exist.' in /Users/user/Dropbox/localhost/yii/framework/web/auth/CDbAuthManager.php:203
Stack trace:
#0 /Users/user/Dropbox/localhost/yii/framework/web/auth/CAuthItem.php(185): CDbAuthManager->addItemChild('member', 'reader')
#1 /Users/user/Dropbox/localhost/trackstar/protected/commands/shell/RbacCommand.php(56): CAuthItem->addChild('reader')
#2 /Users/user/Dropbox/localhost/yii/framework/cli/commands/ShellCommand.php(144): RbacCommand->run(Array)
#3 /Users/user/Dropbox/localhost/yii/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()
#4 /Users/user/Dropbox/localhost/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand->run(Array)
#5 /Users/user/Dropbox/localhost/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)
#6 /Users/user/Dropbox/localhost/yii/framework/base/CApplication.php(135): CConsoleApplication->processRequest()
#7 /Users/user/Dropbox/localhost/yii/framework/yiic.php(33): CApplication->run()
#8 /Users/user/Dropbox/localhost/trackstar/protected/yiic.php(7): require_once('/Users/user/Dro...')
#9 /Users/user/Dropbox/localhost/trackstar/protected/yiic(4): require_once('/Users/user/Dro...')
#10 {main}
>>
RBAC Command:
<?php
class RbacCommand extends CConsoleCommand
{
private $_authManager;
public function getHelp()
{
return "<<<EOD
USAGE
rbac
DESCRIPTION
This command generates an initial RBAC authorization hierarchy.
EOD";
}
public function run($args)
{
if(($this->_authManager=Yii::app()->authManager)===null)
{
echo "Error: an authorization manager, named 'authManager' must be configured to use this command.\n";
echo "If you already added 'authManager' component in applicaton configuration,\n";
echo "please quit and re-enter the yiic shell.\n";
return;
}
echo "This command will create three roles: Owner, Member, and Reader and the following permissions:\n";
echo "create, read, update and delete user\n";
echo "create, read, update and delete project\n";
echo "create, read, update and delete issue\n";
echo "Would you like to continue? [Yes|No]";
if(!strncasecmp(trim(fgets(STDIN)),'y',1))
{
$this->_authManager->clearAll();
$this->_authManager->createOperation("createUser","create a new user");
$this->_authManager->createOperation("readUser","read user profile information");
$this->_authManager->createOperation("updateUser","update a users information");
$this->_authManager->createOperation("deleteUser","remove a user from a project");
$this->_authManager->createOperation("createProject","create a new project");
$this->_authManager->createOperation("readProject","read project information");
$this->_authManager->createOperation("updateProject","update project information");
$this->_authManager->createOperation("deleteProject","delete a project");
$this->_authManager->createOperation("createIssue","create a new issue");
$this->_authManager->createOperation("readIssue","read issue information");
$this->_authManager->createOperation("updateIssue","update issue information");
$this->_authManager->createOperation("deleteIssue","delete a issue");
$role=$this->_authManager->createRole("member");
$role->addChild("reader");
$role->addChild("createIssue");
$role->addChild("updateIssue");
$role->addChild("deleteIssue");
$role=$this->_authManager->createRole("owner");
$role->addChild("reader");
$role->addChild("member");
$role->addChild("createUser");
$role->addChild("updateUser");
$role->addChild("deleteUser");
$role->addChild("createProject");
$role->addChild("updateProject");
$role->addChild("deleteProject");
}
}
}
?>
I think you need to create the "reader" operation (or task, or role) before you can add it to the "member" role with addChild(). Something like this:
<?php
// define reader role
$role=$this->_authManager->createRole("reader");
// add some operations
$role->addChild("readIssue");
// NOW create the member role
$role=$this->_authManager->createRole("member");
// and now that reader is defined, we can add it to member
$role->addChild("reader");
?>
I'm sure you have already found this, but there are more details on the Yii Guide page for Role-based ACL.