I have a page that displays a lot of data, including Zend_Paginator.
The page action is /po/fetch?id=someID.
what i want to do is to pass the "id" parameter to zend paginationControl so the pagination links will be something like /po/fetch?id=someID&page=somePage. unfortunally i can't find anywhere explanation on how i can pass that parameter to the paginationControl.
my call to paginationControl:
echo $view->paginationControl($paginator, 'Sliding',$control, $params);
where $params = array('id' => someID
and my pagination partial is:
First
< Previous
<?php
foreach($this->pagesInRange as $page) {
?>
.$page. | ;
<?php
}
?>
Next >
Last
and I want $url to be of the specified form.
$this->id
Hey Try this, It will surely work.....
<a href="<?php echo $this->url(array('page' => $page,'id'=>'1')); ?>">
<?php echo $page; ?>
</a>
Here 1 is given as the id you have to pass the id you want.......
Like
<a href="<?php echo $this->url(array('page' => $page,'id'=>$param['id'])); ?>">
<?php echo $page; ?>
</a>
Your example code doesn't show how $url is populated, but you really should be using the URL ViewHelper.
So, for example - your previous link would become:
< Previous
This will return a proper URL to the current page with the page parameter set to $this->previous. So if the current url is /users/view?foo=bar&page=5, the above code would output /users/view?foo=bar&page=4 for the previous link. Notice how any query parameters that are already present are preserved.
So, if the id parameter is already present on the URL showing your paginator, the above code will "just work". However, if you still need to add the id parameter, you can do so like this:
< Previous
To continue from our previous example, this code would output the following url: /users/view?foo=bar&page=4&id={someId}
Here is the reference documentation for the URL ViewHelper:
url($urlOptions, $name, $reset):
Creates a URL string based on a named
route. $urlOptions should be an
associative array of key/value pairs
used by the particular route.
One last note - the $reset (third) parameter of the URL ViewHelper will come in very handy. The default behavior is to preserve any query parameters of the current request but calling $this->url(array(), 'default', true) with true for the $reset parameter will basically remove all parameters except for the ones you specify in $urlOptions.
I have gone through the same issue so I have used code given below in partial paginator.
I have created a function in paginator partial view file(control.phtml) or may be different.
function queryStr($p){
$params = $array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();
$params['page']=$p;
$str='?';
foreach($params as $k=>$v){
if($v)
$str .= $k.'='.$v.'&';
}
return $str;
}
Now for links I am using code given below.
<a href="<?php echo queryStr($page); ?>">
Instead of
<a href="<?php echo $this->url(array('page' => $page)); ?>">
I am sure it will be helpful to others as well.
Related
I am using jqxgrid in codeigniter to display records from mysql database. while displaying the data, I made a column named 'action' that contains edit a tag to redirect to another page for editing a specific record. I need to assign id to href attribute in order to do that. but I can't correctly do that.
In controller, tax.php:
foreach($result as $row){
$data[$i]['tax_id']=$row['tax_id'];
$data[$i]['tax_name']=$row['tax_name'];
$data[$i]['action']='Edit';
$i++;
}
how can i correctly assign tax_id to my URL?
I believe you have to evaluate $row["tax_id"] as a PHP expression:
$data[$i]['action']='Edit';
Edit: Use PHP's string concatenation to construct the <a> element:
$data[$i]['action']='Edit';
This is how you do it.
<?php
foreach($result as $row)
{
$editurl = base_url() . 'admin/edit-user/' . $row['tax_id'];
?>
<a href="<?php echo $editurl; ?>" class="edit-user" >Edit</a>
<?php
}
?>
Do let me know if it didn't work.
Use below code:
$id = $row["tax_id"];
$data[$i]['action']='Edit';
It will work properly.
Here I am counting the number of persons a profile owner is following, and the output number is link to open a new page were all persons being followed will be displayed, the count works well and gives the number of persons being followed but now to complete my next page say following.php where all persons being followed will be displayed I need to pass variable $id to that page for which I want to use url method, please help me on this.
<?php
$checkfollowing =$db->prepare("SELECT * FROM follow_user WHERE uid_fk=:id");
$checkfollowing->execute(array(':id'=>$id));
$count = $checkfollowing->rowCount(); ?>
<a href='following.php' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
you can pass value by url and get the value on other page by using $_GET method.
check the below code.
<a href='following.php?id=<?php echo $id ; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
<a href='following.php?id=<?php echo $id; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
you can pass a variable through url by specifieng your variable at end of your url. like this
<a href='following.php?count=<?php echo $count; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
I'm developing a multilang site. The content generated on the varible that passes in the url. Exemple for about us page my url is: domain.com/file.php?id=1 I got one main file and in that file the query gets the id of the selected menu.
If I change the language my url turns to domain.com/file.php?id=1&lang=en. Every time I change the language my url adds one more lang like this: domain.com/file.php?id=1&lang=en&lang=fr&lang=de&lang=en.....
in other multilang project I used this: header("location: ".$_SERVER['SCRIPT_NAME']); But the it were less dynamic pages. like this: domains.com/aboutus.php. I mean: the number of pages were static. The user cannot add or remove pages.
This time because I pass the page id in the url I tried header("location: ".$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']); but it gives an redirect cycle error every time I try to change the lang.
UPDATE
Code to select the languages:
<?php $actual= $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];?>
<div id="langContainer">
<span><a <?php if ($_SESSION['idLang']=='en') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=en">EN</a></span>
<span><a <?php if ($_SESSION['idLang']=='fr') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=fr">FR</a> </span>
<span><a <?php if ($_SESSION['idLang']=='es') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=es">ES</a></span>
<span><a <?php if ($_SESSION['idLang']=='de') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=de">DE</a></span>
</div>
in my session.php
if (!isset($_SESSION["idLang"]) )
$_SESSION["idLang"] = 'en';
if (#isset($_GET["lang"])){
$_SESSION["idLang"] = $_GET['lang'];
//header("location: ".$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
}
So my question is if there's anyway I can get my url cleaner, hidding the lang variables?
Thanks
Dynamically build query parameters, replacing exiting ones in the current URL:
<a href="...?<?php echo http_build_query(array('lang' => 'foo') + $_GET); ?>">
I'm trying to add a 'back' link within page.tpl.php (replacing a proper breadcrumb for a certain content type...).
My goal is to create a link that pulls in the current URL, but removes the final argument. So a page mysite/x/y would have a link mysite/x/ (or mysite/x).
Is this possible? (The URLs are aliased).
<?php
$path = ???
$my_link = l('Back', $path);
?>
<?php if (($node->type == 'marketplace_item')): ?>
<div id="breadcrumb" class="nav"><?php print $my_link; ?></div>
<?php endif; ?>
Cheers,
James
if this the case always you can build the URL manually
$my_link = $base_url . arg(0);
or count the args then remove the last one
Wordpress provides a function called "the_permalink()" that returns, you guessed it!, the permalink to a given post while in a loop of posts.
I am trying to URL encode that permalink and when I execute this code:
<?php
print(the_permalink());
$permalink = the_permalink();
print($permalink);
print(urlencode(the_permalink()));
print(urlencode($permalink));
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url);
print(urlencode($url));
?>
it produces these results in HTML:
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http%3A%2F%2Fwpmu.local%2Fgraphjam%2F2008%2F11%2F06%2Ftest4%2F
I would expect lines 2, 3 and 5 of the output to be URL encoded, but only line 5 is so. Thoughts?
According to the docs, the_permalink prints the permalink vs returns it. So, urlencode isn't getting anything to encode.
Try get_permalink.
[EDIT]
A little late for an edit, but I didn't realize the print counts were such an issue.
Here's where they're all coming from:
<?php
print(the_permalink()); // prints (1)
$permalink = the_permalink(); // prints (2)
print($permalink); // nothing
print(urlencode(the_permalink())); // prints (3)
print(urlencode($permalink)); // nothing
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url); // prints (4)
print(urlencode($url)); // prints (5)
?>
the_permalink() echoes the permalink
get_the_permalink() returns the permalink so it can be assigned to a variable.
(same goes with most functions in WordPress: the_something() has a get_the_something() to return value instead of echoing it)
#Jonathan has the reason why, and the way you should deal with it in WordPress (ie. use the right function for the job).
Here is how to fix it when there isn't a function that returns a string:
ob_start();
the_permalink();
$permalink = ob_get_clean();
print(urlencode($permalink));