Re: pass variable from beforeFilter in app_controller to child controller
On Apr 10, 11:16 am, qwanta wrote: > I am setting a variable value that in app_controller beforeFilter, and > I would like to access it in all child controllers beforeFilter > function. > > class AppController extends Controller { > var $components = array('Auth'); > var $uses = array('User'); > > $auth_id = $this->Auth->user('id'); > if ( $auth_id ) { > $auth_role = $this->User->getRole($auth_id); > } > > } > > class XController extends AppController { > (...) > function beforeFIlter() { > parent::beforeFilter(); > if ($auth_role == "calibrator") { > (...) > } > } > > } > > When I call a method in XController. I get an $auth_role not defined > error. Is there a way to pass the variable value to the child > controller? > Thanks one way could be ~ set your $auth_role as a property of AppController: class AppController { public $auth_role; function beforeFIlter() { $this->auth_role = whatever(); } } class XController extends AppController { function anyFunction() if ($this->auth_role = blah) { } } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
does cake schema handle foreign keys?
I am using $ cake generate schema but see no mention of my foreign keys, using mysql/InnoDB. Am I doing something wrong? regads~ Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: AuthComponent: reset session info on user->save()
That's brilliant and simple, thanks for that. I boiled it down a bit to something that fits right into the AuthComponent, as follows. Not sure if it is core-worthy as I am fairly new with cake, but I will use it via a subclass of AuthComponent for now (since it looks like I will have one anyway for other reasons) /** * Reloads the given field and value within in the session. If no arguments * are given, will read the AuthComponent::userModel and re-load the Session * using the result. * * @param string $field * @param string $value * @return void */ function refresh($field = '', $value = '') { if (!empty($field) && !empty($value)) { $this->Session->write($this->sessionKey .'.'. $field, $value); } elseif ($user =& $this->getModel()) { $this->login($user->read(false, $this->user('id'))); } } cheers ~ Sam On Apr 2, 5:27 pm, Miles J wrote: > The auth session never resets itself unless you log back in. I created > this method below: > > /** > * Refreshes the Auth to get new data > * @param string $field > * @param string $value > * @return void > */ > function _refreshAuth($field = '', $value = '') { > if (!empty($field) && !empty($value)) { > $this->Session->write($this->Auth->sessionKey .'.'. > $field, > $value); > } else { > if (isset($this->User)) { > $this->Auth->login($this->User->read(false, > $this->Auth->user > ('id'))); > } else { > > $this->Auth->login(ClassRegistry::init('User')->findById($this->Auth->user('id'))); > > } > } > } > > Place that in your app_controller and call it like so: > $this->_refreshAuth('email', 'newem...@domain.com'); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
AuthComponent: reset session info on user->save()
Is there any easy way I am missing to reset the values saved in the session under Auth()? For instance when a logged-in user edits their own profile, and changes their timezone. The $model->Auth->user('timezone') is still returning the old timezone from when they first logged in. Have tried calling login() and startup() again to no avail, the data structure it expects is not what I have from $this->data in the controller. Also found this and tried something similar, but seems a bit kludgey. http://groups.google.com/group/cake-php/browse_thread/thread/b1e1012e5dfe112a/2fdd09f820a8bcd9?lnk=gst&q=AuthComponent#2fdd09f820a8bcd9 can I propose/offer a method like $model->Auth->reload($this->data) that would merge the existing stuff under Auth->sessionKey with the passed array? Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
DB down, don't panic
I have a cake app on a server on which the database (mysql) has been going down every couple weeks or so. I think I fixed that problem with mysql, but here is the small problem I have with cake: with Config.debug=0 cake seems to silently ignore the fact there is no database. This makes for some strange behavior - pages aren't populated with content, menus are empty, searches return nothing. with Config.debug=1 then you get a lot of WARNING this and that and then a message about "table not found" either way, my poor client gets very anxious when they see this and sends me emails in ALL CAPS So is there a way, maybe just in my default layout view, to detect if there is no valid DB connection and then display an message along the lines of: http://www.damninteresting.net/content/tech_diff.jpg thanks guys. -Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
thanks for the explanation on calling Behaviors... On Feb 12, 9:20 am, grigri <[EMAIL PROTECTED]> wrote: > This way, if controller "CategoriesController" works on model > "Category", then the following links will work without any extra > controller or model code whatsoever: > > /admin/categories/move_up/{id} > /admin/categories/move_down/{id} this is very cool. So this calls $CategoryController- >admin_move_up(id) ... I assume you use a route to map that, or is there some other magic going on? (not to change the subject) > [I even have a generic helper to make a mini-toolbar with view, edit, > delete and move options for a given model, so in most cases I just go > echo $tool->bar($id) for each record, and it works transparently. I'm > in to writing as little code as possible to get the job done.] Nice! I will have to try that at some pint. cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
On Feb 12, 9:16 am, Baz <[EMAIL PROTECTED]> wrote: > May not be your best bet, but can't you start a transaction and retry until > complete? Well a transaction is good and useful, but it only contains writes, so it still allows Thread B to come along and read the old position values the instant before Thread A makes its UPDATEs. Then as Thread B finishes its UPDATEs based on the now out-of-date values, it screws things up. Of course this is super rare and may take millions of tries. My current app has 5 list items and one administrator, so not much of a worry. But if you have a lot of concurrent users then it could eventually happen. > On Feb 12, 2008 7:49 AM, sbeam <[EMAIL PROTECTED]> wrote: > > > > > On Feb 12, 5:59 am, wirtsi <[EMAIL PROTECTED]> wrote: > > > so I'll just go over to this thread with my problems :) > > > sorry for derailing your thread ;) > > > > ... > > > function beforeSave() > > > { > > > $this->query("LOCK TABLE {$this->table} AS Framejob WRITE, > > > {$this->table} WRITE, > > > queues AS Queue WRITE,jobcolumns as Jobcolumn > > > WRITE,storages as Storage WRITE, > > > lenscolors as Lenscolor WRITE,framecolors as > > > Framecolor WRITE,names as Name WRITE"); > > > > } > > > > Any idea what to do? > > > I think you are describing a classic race condition. > >http://en.wikipedia.org/wiki/Race_condition > > > A problem for sure, the list ordering may run perfectly for years and > > then blow up one day while you are on vacation. > > > I don't think you will be able to fix it with LOCK TABLES in mySQL. > > Hopefully you are using InnoDB anyway and it becomes irrelevant. LOCK > > TABLES can't prevent Thread B from reading the table, which is what > > you need to do. > > > In mySQL maybe you can try GET_LOCK() > > >http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#f... > > > So run "SELECT GET_LOCK('L1',10)" before you proceed. If Thread B > > comes along and needs to wait until Thread A is finished doing it's > > business, then it will (i think ---haven't tested) > > > how then to make it DB-agnostic is another issue. Anyone? > > > have fun > > Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
On Feb 12, 5:59 am, wirtsi <[EMAIL PROTECTED]> wrote: > so I'll just go over to this thread with my problems :) sorry for derailing your thread ;) > ... > function beforeSave() > { > $this->query("LOCK TABLE {$this->table} AS Framejob WRITE, > {$this->table} WRITE, > queues AS Queue WRITE,jobcolumns as Jobcolumn > WRITE,storages as Storage WRITE, > lenscolors as Lenscolor WRITE,framecolors as > Framecolor WRITE,names as Name WRITE"); > > } > Any idea what to do? I think you are describing a classic race condition. http://en.wikipedia.org/wiki/Race_condition A problem for sure, the list ordering may run perfectly for years and then blow up one day while you are on vacation. I don't think you will be able to fix it with LOCK TABLES in mySQL. Hopefully you are using InnoDB anyway and it becomes irrelevant. LOCK TABLES can't prevent Thread B from reading the table, which is what you need to do. In mySQL maybe you can try GET_LOCK() http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock So run "SELECT GET_LOCK('L1',10)" before you proceed. If Thread B comes along and needs to wait until Thread A is finished doing it's business, then it will (i think ---haven't tested) how then to make it DB-agnostic is another issue. Anyone? have fun Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
On Feb 12, 4:46 am, grigri <[EMAIL PROTECTED]> wrote: > I use that code in a lot of (admittedly small) projects, and although > it fits my needs, if you can suggest improvements/enhancements, I'd be > glad to hear them. But "it didn't quite work" doesn't really give me a > lot to work with. no doubt, my intention there was not to give a full bug report exactly ;) I tried the code and it seemed to update the position field incorrectly, breaking the sequence. But last night I figured out that I was calling it wrong from the controller, guessing from the function def., like this: $this->Project->moveUp($this->Project, $id); which of course is seriously wrong. First time using a behavior in Cake so I didn't know how to call it (and yes I did search and read). So your code is probably OK, may just need a line in the comments to show future noobs how to call it properly? $this->Project->moveUp($id); I know it is sometimes hard to understand how noobs can be so stupid, but that's just how it is ;) cheers, Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
On Feb 11, 5:46 pm, AD7six <[EMAIL PROTECTED]> wrote: > b) addresses exactly what you were asking for > c) the code I posted /borrows/ logic from the tree behavior - it's is > not for hierachial data it's for flat lists. none of which is /obvious/ except to you, the author > Don't worry though I'll remember not to point out the obvious to you > in the future works for me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
look, thanks for the finger wagging and challenge to a sword fight but I'll pass. I did find the thread and the code you linked to a long time ago. I rejected it because the comments mentioned MPTT, which again I don't need, plus it is totally incomprehensible to me. I tried the grigri stuff too but it didn't quite work. In any case I did also find this which is almost working and is more clear: http://bin.cakephp.org/saved/21838 I am new to Cake and expected this to be in Bakery, so when it wasn't I thought I would ask if there was any progress I was missing, besides these heaps of code in pastebin which I didn't understand. Sorry if my post disturbed you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: behavior acts_as_list
On Feb 11, 3:11 pm, AD7six <[EMAIL PROTECTED]> wrote: > Please use the search before posting > > http://groups.google.com/group/cake-php/browse_thread/thread/ed4ae9a2... As I said I did search, and that didn't suit my needs because it seemed like it was suited for MPTT trees or something, I am just dealing with a linear list. Thanks for the replay though. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
behavior acts_as_list
hey folks, I need something like acts_as_list in RoR - I found some old threads on here where people were mentioning working on it for 1.2. So has anyone made any progress on it? I have a basic version implemented as a method reorder() of my model. But I'd like to get a more robust behavior if it is out there. If not, I will be glad to contribute if possible thanks Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
SOLVED Re: cake is ignoring my hasMany/belongsTo (noob)
sorry folks I had model/project.php named as model/projects.php - I finally realized Cake was ignoring the whole thing, without complaining. So moral of the story - watch your cases and inflections! just like ROR, figuring out what should be plural/singular or camelCase/under_score_separated is a PITA (esp. for noobs) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
cake is ignoring my hasMany/belongsTo (noob)
I am starting out with Cake after messing with RoR for a while. I jumped right in with a project where 'ArtWorks' are organized into 'Projects'. I wrote it all thusly: === class Project extends AppModel { var $hasMany = array('PubWorks' => array('className' => 'ArtWork', 'foreignKey'=> 'project_id', 'dependent' => true, 'exclusive' => false)); } - class ArtWork extends AppModel { var $belongsTo = array('Project' => array('className' => 'Project', 'foreignKey' => 'project_id' ) ); } class ProjectsController extends AppController { function show($id) { $w = $this->Project->read(); print "DEBUG: at line " . __LINE__ . ' of ' . __FILE__ . "\n"; print_r($w); print ''; } } = I have set up the DB correctly with FKs using mySQL InnoDB. And entered some sample data. But when I call http://localhost/projects/show/2 I get the debug dump of: DEBUG: at line 8 of /xxx/cake_1.2.0.6311-beta/app/controllers/ projects_controller.php Array ( [Project] => Array ( [id] => 2 [name] => War Room [begin_date] => -00-00 ) ) = no sign of the ArtWorks belonging to the Project. The SQL dumps show the artworks table was never queried. I am out of ideas, according to the manual this should work right? What am I missing? thanks Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---