I got a form, that send post request and show paginated results. There are problems, when i want to see pages number 2 and more, because there sended get request and controller doesn't see form to create query. Anyone know how to solve this problem?
I'm using symfony(1.4) and I dont know if there's a big difference between 2.x
so let me discuss about it...
creating url's you should use
<?php url_for('page/view?num='.$page_num) ?>
something like that, then you can now use the request of your module
#app/{apps_name}/module/page/{actions.class.php} or {pageActions.class.php}
to your view method
public function executeView(sfWebRequest $request)
{
$page_num = $request->getParameter('num');
echo $page_num;
}
you should get what the page number now.
one more thing, this only works in $_GET requests.
You should know how to use Routing, to configure atleast 3 parameters. It will help you to use $_POST requests.
I think easiest way would be to make the search a get request so that is in the url. Then the paginated links will have the search value too.
Related
I want to have a following condition in my view.ctp. I want to get the parameters like "/?parameters=name&data=1" from a url and have it in my view. I want to set a $_GET. Where can I set it? Controller,Element,lor View? I read multiple tutorials but I still dont get how the $_GET works in Cakephp2. It would be great if you can give me sample or hints for dummies like me.
if(!empty($_GET['parameter'])){
}
$_GET['parameter'] should be $_GET['parameters'] in your code. For your /?parameters=name&data=1
Im looking for an elegant way to hand over data/params when using $f3->reroute();
I have multiple routes configured in a routes.ini:
GET #sso: /sso/first [sync] = Controller\Ccp\Sso->first, 0
GET #map: /map [sync] = Controller\MapController->second, 3600
Now I reroute(); to #map route, from first();
class Sso {
public function first($f3){
$msg = 'My message!';
if( !empty($msg) ){
$f3->reroute('#map');
}
}
}
Is there any "elegant" way to pass data (e.g. $msg) right into $MapController->second(); ?
I donĀ“t want to use $SESSION or the global $f->set('msg', $msg); for this.
This isn't an issue specific to fat-free-framework, but web in general. When you reroute, you tell the browser to redirect the user's browser page using a 303 header redirect code.
Take a minute to read the doc regarding re-routing: http://fatfreeframework.com/routing-engine#rerouting
There seems to be some contradicting information in your question, which leads me to question the purpose of what you are trying to achieve.
If you are rerouting, you can either use the session, cookies, or use part of the url to pass messages or references to a message.
If you do not need to redirect, but just want to call the function without changing the passed parameters, you could abstract the content of the function and call that function from both routes. You could also use the $f3 globals, which are a great way of passing data between functions in cases where you don't want to pass the data using the function call. is there a reason why you don't want to to use this? The data is global for the single session, so there is no security concern, and the data gets wiped at the end of the request, so there is very little extra footprint or effect on the server.
If you're alright with not using #map_name in re-routes you can do something like this:
$f3->reroute('path/?foo=bar');
Not the prettiest I'll admit. I wish $f3->reroute('#path_name?foo=bar') would work.
I'm from ASP.NET MVC background and this is first time I'm trying to write something in PHP.
In ASP.NET MVC we can develop models for our data and using the actions that we write we can get them or send them to another action. What I mean is that
public ActionResult Login_Action(LoginModel _Model) {
// Authenticating the user
return RedirectToAction(X);
}
when calling this the url that is shown in the address bar (in case of using GET, if it is POST nothing will be shown after the page name) will be:
www.WebsiteX.com/Login?Username=something&Password=something
The problem is that I don't even know how search for this in google (like by typing what exactly) because in Microsoft side, these are handled automatically the way I described.
But in case of PHP, how can I get the values in the address bar? do I have to get the actual address and then break the values down into arrays?
I'd appreciate any help.
First of all, this seems to be invalid for me: www.WebsiteX.com/Login?Username=something?Password=something The first parameter need to be ? and the others should be &.
Second: You can get your values of your parameters by accessing the $_GET global array.
Eg. for the username echo $_GET["Username"];
Are you using any framework? You should. And then, the Framework will give you the way to do that. In ASP.NET you use a Framework so do the same in PHP.
With vanille PHP you can get the GET values with $_GET['Username']. But please, use a framework.
I think that the most popular are Laravel and Symfony right now.
Example:
In laravel you can bind a parameter to a variable so you can do something like:
//Url: mywebsite.com/user/1/
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
Which is similar with the ASP.NET example.
I came from Codeigniter. In CI I had this:
$route['([a-z]+)tab'] = "$1/tab";
When I go to index.php/sometab/ I'll get some/tab/ action executed. But it doesn't redirect, instead I just tell CI that when I type this address I want to use another address instead, though there is no redirect.
Basically I want to achieve next goal: when I go to /someTab/ I want to execute some#tab action.
I only found Redirect::to_action in laravel, but I dont want the URL to be changed. I tried something like:
Route::any('([a-z]+)tab', function($controllerName) {
return Redirect::to_action("{$controllerName}/tab"); // here I want to tell to use $controllerName#tab action
});
How can I get this?
http://laravel.com/api/class-Laravel.Routing.Controller.html
There are some interesting methods here to. Route::cal, Route::forward, Route::execute...
I am thinking of a way to send a request to page, and receive a request from a page and then read it. The problem is that I dont know what is the most efficient way of achieving so.
$result=file_get_contents('scan_results.php');
$scanning=true;
while($scanning){
if(stristr($result,'Nothing to scan.')){
$scanning=false;
}
}
Right now, I simply send a request to the page and try to scrape the page for the sentence 'Nothing to scan.'.
The page scan_results.php, should do a few tasks, so I loop it until I get 'Nothing to scan'.. So basically, I am thinking of using a better way to check when I get the sentence nothing to scan..
Try cURL: http://php.net/manual/en/book.curl.php