magic-methods

Python equivalent of PHPs __call() magic method?

In PHP, I can do something like this: class MyClass { function __call($name, $args) { print('you tried to call a the method named: ' . $name); } } $Obj = new MyClass(); $Obj->nonexistant_method(); // prints "you tried to call a method named: nonexistant_method" This would be handy to be able to do in Python for a project I...

__set and string concatenation

Hello. Im' wondering if this is possible: I've successfully used __set() magic method to set values to properties of a class: class View { private $data; public function __set( $key, $value ) { $this->data[$key] = $value; } } So I'm able to: $view = new View(); $view->whatever = 1234; The problem comes wh...

CakePHP strange behavior with beforeFilter: I cannot set the variables to the view.

Okay, this will require some setup: I'm working on a method of using nice post title "slugs" in the URL's of my cakePHP powered blog. For example: /blog/post-title-here instead of /blog/view_post/123. Since I'm obviously not going to write a new method for every post, I'm trying to be slick and use CakePHP callbacks to emulate the beh...