hi i create one custom page in WordPress like page-download.php
i access this page like
http://example.com/download
its word fine but i want access this page like
http://example.com/download?n=skype
http://example.com/download?n=firefox
etc every time n value change.
and also i want get n value in page-download.php
please tell me how to do it . i know how to work in php simple but in wordpress its not work
Why just not use, echo $_GET['n'] ?
When you hit this page directly from the URL like below, please change your parameter, because of that I have tried same method few days ago and I can't get the parameter value.
http://example.com/download?from_browser=skype
http://example.com/download?from_browser=firefox
You can get the value like below or as per the reference :
$blah = get_query_var( 'from_browser');
if(isset($blah)) // Your code will be here
Hope this help!!!
Related
In my website I need to customise the url ,
I done it some way ,everything is working fine .I got what I need ,but I want to do it in a proper way .
Below is my code
$route['admin/lessons'] = 'admin/admin/lessons';
$route['admin/lesson_mgmt'] = 'admin/admin/lesson_mgmt';
$route['admin/labs'] = 'admin/admin/labs';
$route['admin/tools'] = 'admin/admin/tools';
Here in this way I am managing the custom url section .
I want to make this url dynamic so that ,the code will not be longer ,there are other section .
If i will do it in this way ,I have to write a lot .
Here i want to replace everything in a single line.
Can anyone suggest me anything ?
Thank you in advance.
Try like this...
In your application/config/routes.php
$route['admin/([a-zA-Z0-9_-]+)'] = 'admin/admin/$1';
Hope it will work fine..
In above code.. [a-zA-Z0-9_-]+) this is regular expression having combination of one or more alphanumeric characters(alphabets+numbers).If route gets admin/characters...it redirect to admin/admin/characters.
I am trying to add a custom link to a custom page using the vtiger_link table, with 2 parameters; 1 is the trouble ticket id which works fine:
This is in the URL field in the database:
modules/Helpdesk%20Info/index.php?ticketid=$RECORD$"target='helpdeskinfo'
and 2 is the id of the logged in user ($current_user) but it doesn't work:
modules/Helpdesk%20Info/index.php?ticketid=$RECORD$&$user=$current_user"target='helpdeskinfo'
It shows the page just as it should, but the variable $user gets the value '$current_user':
http://localhost:8888/modules/Helpdesk%20Info/index.php?ticketid=135409&$user=$current_user
I wanted to post a picture of the table, but I don't have enough reputation for that.
I have tried many things, but I am clearly doing something wrong.
Any help would be much appreciated.
I did not need to put the variable in the URL,
the reason I could not use the $current_user variable is because it didn't exist in "detailview.php" which is where the link ends up.
I used:
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
to view all globals, there I found the authenticated_user_id
Knowing I could use this I was able to access the global from my file without the URL:
$current_user = $_SESSION["authenticated_user_id"];
I would like to thank STT LCU for his advice, as he was the only one who helped me through this problem, which took me a full week in total.
I'm trying to perform a mass assignment of 2 variables I'm sending via GET to another model::controller (from project::actionCreate to client::actionCreate)
In the _form view for project::actionCreate I've got the following:
<?php echo " ".Chtml::link('+New client',array('client/create',array('Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id))));?>
With the goal of creating an array "Client" with attributes "redir" and "redirId".
In client::actionCreate I want to do something like
if(isset($_GET['Client']))
{
$model->attributes=$_GET['Client'];
}
Now I noticed that my $_GET var puts client inside subarray 0, so I've tried this with
$_GET[0]['Client']
as well, but no luck. However if I manually assign the variables like this:
$model->redir = $_GET[0]['Client']['redir'];
$model->redirId = $_GET[0]['Client']['redirId'];
Then it works.
Any idea what is up? The goal is to allow someone to create a new client while creating/updating a project record, by sending them to client::actionCreate, but redirecting them back to their original project::actionCreate if they were linked there from my "+New Client" link.
I think the client array is put inside subarray 0 because you've added an array around the parameters. Try removing the array like the following:
<?php
Chtml::link('+New client',array('client/create', 'Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id)));
?>
I don't know what your model looks like but if the fields aren't assigned they are probably not safe. You can make them safe by adding them to the rules part of your model. Or you could try the following, by specifying the false parameter it will be possible to assign values to unsafe attributes. (http://www.yiiframework.com/doc/api/1.1/CModel#setAttributes-detail)
$model->setAttributes($_GET['Client'], false);
I am not sure creating a link like you want is possible. I have asked something similar some time ago Yii link with [ as a parameter I just could never get the link to how I wanted it. In the end I just created the link the old fashion way, not using CHTML.
I have created pagination item by CodeIgniter pagination library with following code:
echo $this->pagination->create_links()
Everything is working well.
Now i want to load data by ajax and i have done already ajax part. But problem is to make clicked item as a current item and to arrange link for current item as it is no longer current.
Suppose i have a pagination as following:
[1] 2 [3] [4] [5] [6] [>] [Last >]
Now 2 is current item and 4 is clicked item.
I have checked CodeIgniter Pagination library, but it doesn't have any option to enable or disable current page link. Is it possible to have current page link without modifying the library?
Thanks in advance.
I take it all back. The Pagination library will need to be changed.
https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Pagination.php
Line 560
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close
Will need to be replaced with
$append = $this->prefix.$i.$this->suffix;
$output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'.$loop.'</a>'.$this->num_tag_close;
That should do it.
You don't need to modify anything on server side. just use plain old vanila jquery.
Here's how to do it.
Let's say i wrapped the links in a <div id="pagination"></div>
Now, to call ajax, use jQuery(body).on('click','#pagination a', function(e){....}).
Here in this code, jQuery(this) will refer to the link that was clicked.
Next, after successful call, remove the active (or any other class that is given ) from all the links. like jQuery('#pagination a').removeClass('active').
Next, if you still remember, jQuery(this) still refered to the current clicked item. (better save it as var current = jQuery(this) at the start of the clicked even so that the reference does not change. Now, just add the class. jQuery(current).addClass('active')
You are done! No need to do anything fancy anything in server side. Sometimes client side is enough.
P.S. i forgot how CI renders the pagination links. if you give the links, i can write the actual code.
var_dump($this->pagination); everything is inside
then if you check Pagination.php library you have these params available too:
var $cur_tag_open = '';
var $cur_tag_close = '';
so try calling them when initializing pagination
$pagination['cur_tag_open'] = '<span class="current-link">';
$pagination['cur_tag_close'] = '</span>';
$this->pagination->initialize($pagination); //now current link should be wrapped into the <span class="current-link"></span>
I don't believe you need to change anything in the Pagination library. You just need to use the uri_segment() function.
The Pagination library takes an argument as follows:
$config['uri_segment'] = 5;
The default value is 3. [Use a value that will work with your URI structure].
This variable is used along with the uri_segment() function to determine the current page, in the latest version of CodeIgniter 2.1.4 you will find it starting on line 142 in the Pagination.php library.
The appropriate uri_segment for the page identifier could be calculated as follows, if using a URI like this one: http://example.com/controller/function/page/20 then you can get the current page as follows,
$page = $this->uri_segment(4);
Hope that helps.
You really dont need to change anything.
Once you have your automatic page set
$page = 2 // Page should be set automatically
Now try this
$config["cur_page"] = $page;
I have some questions concering routing with Codeigniter. What I´m doing now is the following:
$route['articles/(:num)'] = 'articles/view/$1'; // $1 will contain an ID
This means that example.com/articles/123 will work perfectly and load an article with an ID of 123. But I also want to have the possiblilty to add the aticle´s title to the URL (for SEO). Example: example.com/articles/123/article-title
What I want is pretty much the same thing as Stack Overflow: stackoverflow.com/questions/123/the-title
How can I do that?
I´m also wondering how Stack Overflow works. If I go to stackoverflow/questions/111 the title will automatically be added to the url. Is that done with php redirect()?
I have done something similar in the past; I can't find it know but IIRC (it was months ago) You can use a route like you did, and also add a more specific one, like
$route['articles/(:num)/(:any)'] = 'articles/view/$1/$2';
$route['articles/(:num)'] = 'articles/view/$1';
As you can see, both map to the same method, which is kind of "overloaded"; you can make up for a missing parameter by using a default value:
function articles($id,$slug = FALSE)
{ }
and simply ignore the second parameter in your article retrieval.
As for adding the title you can:
have a "slug" field in your database, created when the article is saved. You can use the comfortable url_title($title,'dash',TRUE) function (in the url helper), which takes the $title, uses the dash as separator, and make it all lowercase;
use the above function and convert the title of the article (after you retrieved it from the database) "on-the-fly"; just check on the article() method if the 2nd parameter isn't false and you'll know if you need to create the slug or not;
As for how to show the slug even when using an url without it you can make, as you guessed, a redirect, but since both routes point to the same method it won't change anything for you.
Oh, uhm, beware of loops while calling the redirect, check carefully ;)
I suggest you to create a slug field into your table and complete it with the url you want to use as id.
Let me explain.
You have this table
id
title
slug
when you save an article into your db you can dinamically create a slug, for example:
id: 1
title: My first post
slug: 1-my-first-post
then you can use the slug (in this case 1-my-first-post) ad id for the page, you can call it:
www.example.com/articles/1-my-first-post
obviusly you need to handle it in your db slect
As we discussed on the comments.
You can create a route several times and with different parameters each, like:
$route['articles/(:num)/(:any)']
$route['articles/(:num)']
I would create a function with a redirect, adding or not the title to it.
Hope it helps.