redirect to any url
This was posted by me. Seems that my session expired while I was typing the message, so my name isn't in the message.
Posted June 28th, 2007 at 2:59am by telega
Part of the reason that there has been such a huge gap in releases (besides being really busy and having my personal life go crazy (in a good way)), is that a lot has been re-written. Right now I still use header('Location: ...') to do certain redirects that aren't to specific actions. I see no shame in that. A lot of routing problems are solved in the next release, however I am going to flag this post and read over it again once the new release is out. I'll also try and figure out the session bug, bit me once but I couldn't duplicate it. Thanks for your suggestions and reports!
Posted June 28th, 2007 at 11:22am by ryan
I should also add, that the variable setting mechansim is now much more rails like, and causes less confusion. You can still manually specifiy, but I think that error as well is solved.
Posted June 28th, 2007 at 11:26am by ryan
Just my point about Routing ...
Have you check how CodeIgniter routing module works ? you can match regex in the route or wildcard like :any or :num that are really usefull I think.
so you routes can look like:
array('/page/:num' => '/page/show_by_num/$1',
'/page/:any' => '/page/show_by_title/$1');
I think is a other technic, that can be use and it is good to know !!
Posted June 29th, 2007 at 8:46am by philippe
Interesting! I'm going to have a look.
Posted June 29th, 2007 at 9:38am by ryan
I have forgot to specify that if you need more regex or wildcard in once route you can too
array('/bolg/:any/:num' => '/blog/view/$1/$2',
'/blog/:any' => '/blog/view/$1');
and your controller will look like:
class BlogController extends Controller {
public function view($title, $page=1) {
...
}
}
that's it !!
Posted June 29th, 2007 at 2:28pm by philippe
One more feature would be nice to have - two routes mapping to the same method: (for example to implement paging)
PicoraDispatcher::addRoute('/category/$id/', array('Shop','category'));
PicoraDispatcher::addRoute('/category/$id/$page/', array('Shop','category'));
so that $controller->getUrl('category', array('id' => 1)) will return the first URL, and $controller->getUrl('category', array('id' => 1, 'page' => 1)) will return the second. Currently $controller->getUrl() in both these cases returns the first URL.
Posted July 7th, 2007 at 5:19am by telega
A problem: when setcookie() is called and then $this->redirect(); is called, the cookie isn't set.
Posted July 10th, 2007 at 9:22am by telega
My bad - setcookie & redirect isn't a Picora problem. The cookie is successfully set, I wasn't able to retrieve it because by default cookie is set to be available only within current directory.
Posted July 11th, 2007 at 3:24am by telega
One more problem I have with Beta 3. A weird problem. I have the following controller:
class Order {
public $items = array();
}
class OrderItem {}
class TestController extends PicoraController {
public function index() {
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = new Order();
}
$_SESSION['cart']->items[] = new OrderItem();
print_r($_SESSION['cart']);
return 'Hello World!';
}
}
When I open the test page for the first time, everything is OK, the page shows:
Order Object ( [items] => Array ( [0] => OrderItem Object ( ) ) ) Hello World!
But when I reload the page, it shows:
Notice: TestController::index() [function.TestController-index]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Order" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in Z:\home\localhost\www\shop\app\controllers\TestController.php on line 13 __PHPIncompleteClass Object ( [__PHPIncompleteClassName] => Order [items] => Array ( [0] => _PHPIncompleteClass Object ( [__PHPIncompleteClass_Name] => OrderItem ) ) ) Hello World!
It says that my Order class is not defined, though it is defined right above the controller class. Can anybody suggest something on this?
Posted July 12th, 2007 at 10:53am by telega
this is because the session is start before the load of you controller class with the order class and orderItem ( I think it is started in the dispatcher )
maybe a good usage to do is to convert your data saved in session in a array and then on the load in your controller class passe this array to the order constructor that will load data in the object and then you will have a nice order object, withou any problem with the declaration of the class order before the session load.
OR
include in the __autoload the Order class and OrderItem class.
hope this can help you !!
Posted July 12th, 2007 at 1:40pm by philippe
Thanks, will add it to autoload().
Posted July 13th, 2007 at 9:33am by telega
Hi
I'm trying to implement a rails-like login in my app using Picora. When user tries to open some page that requires login, url to that page is stored in session, then user is shown a login screen, and on successful login user is redirected to the original url. What I did:
But the problems are: 1) redirect() method allows redirecting only to actions that are registered in PicoraDispatcher 2) beforeCall() method doesn't return a response. I think it would be good to have this changed.
Also I've found two small issues: 1) If I add '/$page/$pageSize/' route to the PicoraDispatcher, then the $controller->getUrl() returns '/1/1Size' url, i.e. it replaces '$page' two times. Though this can be easily workaround by having '/$pageNo/$pageSize' route. 2) I have two subsequent calls to the render() method:
I'm passing an array('category' => $category) as $arguments parameter. And I found that if the first view being rendered uses its own $category variable, this variable overwrites $category value in $arguments array. This happens because of the EXTRREFS parameter in extract(getobjectvars($this),EXTRREFS) call in PicoraView::display() method.
Posted June 28th, 2007 at 2:58am by