How to fix routing with pagination and long variable query strings - symfony1

I have a problem going from page one to page two, three, four, etc... when using pagination along with a long and variable query string. I suspect its a routing issue. I’m using a custom query that the user selects with a series of dropdown menus. The resulting url is very long which contains all of the post variables.
For example, the working first page url looks like (with the post variables represented here as letters):
project/web/s/search_results/t/u/v/w/x/y/z
...and the non-working 2nd page url when page 2 is clicked:
project/web/s/search_results?page=2
The 2nd page is following the routing rule. As mentioned page two doesn’t work as clicked from the pager menu. But if I manually type in:
project/web/s/search_results/t/u/v/w/x/y/z?page=2
-it does work. The important lines of code are as follows:
Routing rule:
search_results:
url: /s/search_results
param: { module: s, action: search_results }
url_for helper in pagination:
<?php foreach ($pager->getLinks() as $page): ?>
<?php if ($page == $pager->getPage()): ?>
<?php echo $page ?>
<?php else: ?>
<?php echo $page ?>
<?php endif; ?>
<?php endforeach; ?>
And the error message:
404 | Not Found | sfError404Exception
Unable to find the s object with the following parameters "array ( 'id' => 'search_results', 'sf_format' => 'html',)").
Should I be using a collection for the routing rule?
Edit:
The object referred to in the url_for helper:
<?php foreach ($pager->getResults() as $o => $object): ?>

Try:
<?php echo $page ?>

Related

Get values from url after a specific portion of html

I need to go to a specific portion of html through url and get the values from url.
Here is my url.
But if i get the value of 'number_page' as,
$_GET['number_page'] it doesn't return anything.
Is there any solution?
Given you are using PHP(implied from your question) and the 'aTag' in my example is the html code of the page you are at:
<?php
$aTag="";
$pos = strrpos($aTag, "number_page=");
$subStr = substr($aTag,$pos+12);
$pos = strrpos($subStr, "'");
echo substr($subStr,0,$pos);
?>
The output will be 10
You can see it here

extract private youtube playlist video links

I am trying to extract the video link of my private playlist. but i am unable to do
I used the below code to get the list
<?php
if(isset($_POST['send']))
{
$cont = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/playlists/'.$_POST['a'].'/?v=2')); ?>
<?php $feed = $cont->feed->entry; ?>
<?php if(count($feed)): foreach($feed as $item): // youtube start ?>
<?php echo $item->{'media$group'}->{'yt$videoid'}->{'$t'} ?>
<?php echo $item->title->{'$t'} ?>
<?php endforeach; endif; }?>
but this doesn't work. i need to extract only link with video title.
i have my account details with me how its possible using php
Since you want a private playlist, this will need to be an authenticated call, so you'll first have to set up an oAuth exchange. In PHP the easiest way to do this is with the gapi client; you can see more info (and get the library and sample code) here:
https://developers.google.com/youtube/v3/code_samples/php#retrieve_my_uploads
It will require you to use the client ID and secret for your registered app, though (don't forget to turn on the YouTube API v3 in the registered app!).
Once the oAuth is working, you can change the sample code listed above to very easily get your private playlist; starting with line 40, you'll have to use a call that's something like this:
$playlistResponse = $youtube->playlist->listPlaylists('contentDetails', array(
'id' => $_POST['a'], // assuming this variable represents the id of your playlist
));
You'll also have to somewhat modify the code after that block to be able to parse the playlist feed and get your info.

How To Get Twitter Followes_Count To echo with commas

I am working on pulling the number of twitter followers into my Wordpress page but running into a small problem I cannot figure out. I imagine it would be a quick fix...do you think you can help?
The issue is the output reads:
11131
I would like it to read:
11,131
You see the comma in the correct position...not sure how to get that to render in the right format. Here is the code I am working with:
<?php
$data = json_decode(file_get_contents('https://api.twitter.com/1/user/lookup.json?screen_name=erinschreyer'), true);
echo $data[0]['followers_count'];
?>
Any help is appreciated...
It would work with that:
<?php
$data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=erinschreyer'), true);
$followers = $data[0]['followers_count'];
echo number_format($followers);
?>
See number_format()

Any smart way to operate production URL while im working in dev enviroment?

I have some code that retrieves the production URL and check some staff.
Im prefer to work in the dev invoroment so I have to write in my code
something like this
<?php if(sfConfig::get('sf_environment') == 'dev'): ?>
<?php $url = "http://www.mysite.com/foobar" ?>
<?php else: ?>
<?php $url = $sf_request->getUri() ?>
<?php endif; ?>
Is there any smarter way to operate production URL while im working in
dev enviroment? Or do you do this kind of things?
Javi
On the projects I work on, I use the app.yml file to take care of things like this.
So in app.yml on dev I have
all:
# site_url: "http://site.com" #Be sure to change this when you deploy, or write a script to do it
site_url: "http://site.dev"
And in my code I would have
<?php $url = sfConfig::get('app_site_url'); ?>
I'm not sure if you're looking for something like this
You can edit your /etc/hosts file and add an entry for mysite.com that goes to your dev server ip address
Wikipedia article should tell location on windows/mac
http://en.wikipedia.org/wiki//etc/hosts#Location_in_the_file_system
(you may have to add one with www.mysite.com also)

Setting baseurl in cakephp

I am working on an application which is running in CakePHP and I am using AJAX queries from within.
In all the cases for all the ajax post i have used the url as
var ht = $.ajax({
type: "GET",
url: "http://172.20.52.99/FormBuilder/index.php/forms/viewChoices/"+attribute_id,
async: false
}).responseText;
var myObject = eval('(' + ht + ')');
Is there any way in CakePHP where I can give my base URL as http://172.20.52.99/FormBuilder/index.php/ and to call the base URL in all the places I want.
Try writing following code
'http://'.$_SERVER['HTTP_HOST'].$this->base
$_SERVER['HTTP_HOST']----it will give you working host
and $this->base---will give you working url
You can use $this->base to get base url.
you may use
<?php echo Router::fullbaseUrl();?>
as well.
Refer http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html for more details.
You could set default URL for all your ajax requests that way:
$.ajaxSetup({
url: 'http://172.20.52.99/FormBuilder/index.php/'
});
Use any one method of following
<?php echo $this->Html->url('/');?>
<?php Router::url('/', true); ?>
<?php echo $this->base;?>
<?php echo $this->webroot; ?>
Define constant in Config/core.php as define("BASE_URL", "www.yoursite.com/"); and use BASE_URL anywhere in your project
I assume I've the same scenario: for development, the site is available at localhost/cake, whereby in production the site is deployed in the root dir of example.com. In the header I set:
<base href="<?php echo $base_url ?>" />,
in AppContoller::beforeRender() I set:
$this->set('base_url', 'http://'.$_SERVER['SERVER_NAME'].Router::url('/'));.
This works fine for everything, except JS (so thus AJAX), as it ignores base_url.
Therefore I have a workaround (uses jQuery, but easy to substitute without):
forUrl = function(url) {
return $('base').attr('href')+url.substr(1);
}
login = function() {
$.post(forUrl('/ajax/profileDiv'), $('#profile-login-form').serialize(),
function(data) {
(...)
});
}
This might also be helpful:
http://book.cakephp.org/view/1448/url
<?php echo $this->Html->url('/posts', true); ?>
//Output
http://somedomain.com/posts

Resources