codeigniter segment method - php

Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of URL at href($this->url->segment(6)) but when i click the link it goes to full URl/6th segment.i.e
I want my link will be go here www.webcoachbd.com(this is 6th segment of my URL)
but it goes http://www.example.com/controller_name/method_name/segment1/segment2/segment3/www.webcoachbd.com

Are you doing this in your view?
I dont know if $this->uri->segment will work inside views, never needed it myself.
Instead grab the URI inside your controller and pass it back to the view.
$this->load->view('some view', array(
'link' => $this->uri->segment(6)
));
-
link
Although I dont really understand why you would want to do that.

Its not url but uri
$this->uri->segment(6);
and i think you are missing = operator in the anchor
MyLink

From the resulting URL that you posted, it looks like you might be missing a forward slash.
link text
This would force the URL to forward to the root of your site, rather than to that location inside the current folder that the browser thinks it is in.

Related

page before url / change url

I created a login website, and my URL became like this
http://localhost/koperasi/index.php/cukl/index
how to make my url like...
http://localhost/koperasi/index.php/cukl
because I want to make a crud program but I think I have a problem in the url
**
my previous program using http://localhost/lee/index.php/buku so my page can entered CRUD on http://localhost/lee/index.php/buku/ubah
but now my newer program url is http://localhost/koperasi/index.php/cukl/index
how and where to change the url? is in the controller? model? or view?
I think, firstly you have to add an htaccess file which will remove index.php in your URL.
and inside the route.php file, you can define a new URL which you want.
Like this.
$route['cukl'] = 'cukl/index';

anchor tag weird behaviour in codeigniter

i have controller by name"job_classified" the problem is when i open
click me
in view it opens http://localhost/my_project/job_classified/google.com instead of google.com
what actually is the problem? i tried other code igniter URI functions but it didn't work for me.can someone guide me how to do it correctly
Why your code doesn't work is described here:- https://stackoverflow.com/a/2005097/4248328
So do like below:-
click me
try this
click me
Please change url to:
click me
Reason: HTML parses urls as of relative ones if no http or https is given.
HTML server in your case considers google.com as a relative file is the same directory.
In Codeigniter you can do it a couple of ways
Using the base_url from the url helper
Note: the base url in config.php must be set
https://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
Some Name
Some Name
Also you can use the anchor();
https://www.codeigniter.com/user_guide/helpers/url_helper.html#anchor
<?php echo anchor('job_classified', 'Job Classified');?>
<?php echo anchor('controller/function', 'Job Classified');?>
How to remove index.php from url
https://github.com/wolfgang1983/htaccess_for_codeigniter
Always prepend URLs with double slash. That way you don't need to think whether location should be http or https.
This way browser will automatically
determine which scheme to use

How to make parameter name in URL default and hidden in Kohana?

I'm trying to make this work. I want my routing to behave like this:
when I type URL ie. example.com/api/getpage/http://smth.com I want to retrieve in my action id parameter with http://smth.com value.
My routing for this case looks like this right now:
Route::set('api', 'api/<action>/<id>')
->defaults(array(
'controller' => 'api',
'action' => 'index'
));
And what's in action:
public function action_getpage()
{
$obj = $this->scrape($this->request->query('id'));
$this->response->body(json_encode($obj));
}
Now URL like this example.com/api/getpage?id=http://smth.com works like a charm, but I don't want it that way. Is there any way to achieve that goal? Thanks in advance for all suggestions.
The problem is you can't use slashes within a url segment (except in get parameters). This has nothing to do with kohana routing but how your web server handles it. The only way around it would be to replace he slashes with something else. You'd also encounter issues if the url you pass as the final segment had get parameters on the end of it, the question mark would be cause it to be treated as get parameters of your main url, not the final segments.
Another option would be to base64 encode the final url segment then decode it inside your controller. This would get rid of any slashes and question marks. Php has simple base64_encode and base64_decode functions. The only downside is tha portion of the url will look like an arbitrary garbled string. http://php.net/manual/en/function.base64-encode.php

Yii urlManager route with query string

This is about setting WebRoot/protected/config/main.php *urlManager* on Yii Framework.
I want a few predefined url like /About /Contact or some other custom special page like /LatestUpdates or /HTCDesire
I can do 'Contact'=>'site/contact' to map /Contact to /site/contact
How can I 'hard code' query string to the route?
I try:
'About'=>'site/page?view=about'
'LatestUpdates'=>'update/view?id=65'
'HTCDesire'=>'product/view?id=33'
but not working, 404 not found because it expect the right side should be route in format controller/action.
I try:
'LatestUpdates'=>'update/view/id/65'
I can browse to /LatestUpdates but the anchor link still shows /update/view/id/65
Is there any other way?
This works for me (except I substituted your values in, so maybe I broke it...):
'LatestUpdates'=>array('update/view','defaultParams'=>array('id'=>'65')),
More about this here and here.
Cheers!

change word in referred url to direct to correct page

I recently changed a word in my query string in my url, which causes the query to break, so I wish to redirect the old url to the new one. example:
http://www.lovelakedistrict.com/result/?q=Windermere&result=2
new url
http://www.lovelakedistrict.com/result/?q=Windermere&page=2
What would be the best solution for this, is there anyway do it in php or is it a htaccess rule?
At the top of your page, you can simply use this hotfix:
if(isset($_GET['result']))$_GET['page']=$_GET['result'];
if(isset($_REQUEST['result']))$_REQUEST['page']=$_REQUEST['result'];

Categories