error 404 Sending value to controller in Hosting CI - php

I have a problem sending value to controller, there is a double on rsport23.000webhostapp.com
https://rsport23.000webhostapp.com/rsport23.000webhostapp.com/pesanan/tambah_form/2
what should I change?
<p><a href="<?php echo site_url('pesanan/tambah_form/'.$value->id_barang); ?>">PESAN SEKARANG
</a></p>

try to use with base_url. always work for me.
<p><a href="<?php echo base_url().'pesanan/tambah_form/'.$value->id_barang; ?>">PESAN SEKARANG
</a></p>

First of all set the base url in the application/config/config.php
$config['base_url'] = "https://rsport23.000webhostapp.com/";
then after that you can do like that:
<p>
<a href='<?php echo base_url("pesanan/tambah_form/$value->id_barang"); ?>'>PESAN SEKARANG</a>
</p>

Related

Codeigniter URI routing is not working

I am using codeigniter framework in my web development and passing the value of image id using php code such below
<a href="<?php echo base_url('account/gallery/view'); ?>?id=<?php echo $imageDetail['imageId']; ?>">
<img src="" />
</a>
and getting the value at controller with this code $imageId = $this->input->get('id');
With the get method I used, it will display the url like this :
http://my-domain-name/account/gallery/view?id=1
But I want to display the url like this :
http://my-domain-name/account/gallery/1
So what I did is setting in the router with this code but it's not working.
$route['account/gallery/(:num)'] = 'default/Gallery_controller/view/$1';
My web still able to show the template of the web if I type http://my-domain-name/account/gallery/1 but display error in the field that I fetch from database because unable to get the imageId
use Regex instead of :num in route.php
$route['account/gallery/([0-9]+)'] = 'default/Gallery_controller/view/$1';
And in your template file:
<a href="<?php echo base_url('account/gallery/'.$imageDetail['imageId']); ?>">
<img src="" />
</a>
Then you can access directly in your gallary controller in view function $id.
eg:
class Gallery extends MY_Controller {
public function view($id){
// Your Image ID = $id;
}
}
Set this url http://my-domain-name/account/gallery/1 proper in href
<a href="<?php echo site_url('account/gallery/view'.$imageDetail['imageId']); ?>">
<img src="" />
</a>
Replace
<a href="<?php echo base_url('account/gallery/view'); ?>?id=<?php echo $imageDetail['imageId']; ?>">
with
<a href="<?php echo base_url();?>account/gallery/view/<?php echo $imageDetail['imageId']; ?>">
Check your config.php
$config['enable_query_strings'] = true;
to
$config['enable_query_strings'] = false;
In this try this (:any)
$route['account/gallery/(:any)'] = 'default/gallery_controller/view/$1';
Or
$route['account/gallery/view?(:any)'] = 'default/gallery_controller/view/$1';
In the routes lower case
This code is make your url like http://domain-name/account/gallery/1
Try this:
<a href="<?php echo base_url();?>account/gallery/view/<?php echo $imageDetail['imageId'];?>">
<img src="" />
</a>

Append a GET variable on to a page with another GET variable

I have a profile.php page with a variable uid?=12 and i have a language bar on that is on a separate page called lang.inc.php:
Profile Page:
<div class="langbar">
<?php include 'inc/lang.inc.php'; ?>
</div>
lang.inc.php
<center>
<a class="flag_USA" title="English" href="<?php echo basename($_SERVER['PHP_SELF']); ?>"><img src="css/images/us.png"></a> <span> </span>
<a class="flag_France" title="French" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=fr"><img src="css/images/fr.png"></a> <span> </span>
<a class="flag_dutch" title="Dutch" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=de"><img src="css/images/de.png"></a> <span> </span>
<a class="flag_Italy" title="Italian" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=it"><img src="css/images/it.png"></a> <span> </span>
<a class="flag_Italy" title="" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=es"><img src="css/images/sp.png"></a> <span> </span>
<?php echo $_SERVER['PHP_SELF']; ?>
</center>
As you can see im trying to append the ?lang=fr for example to the end of the profile.php?uid=12 so it looks like this profile.php?uid=12&lang=fr but all it's doing is profile.php?lang=fr.
I'm pretty sure $_SERVER['PHP_SELF'] does not include get variables, just the file path, so you'd have to add the uid to the href yourself.
<?php
$basename = basename($_SERVER['PHP_SELF']); // Lets store the basename
$basename_with_uid = $basename . "?uid=" . $_GET['uid']; // and append the uid from the URL. Make sure to do some validation if $_GET['uid'] exists.
?>
<a class="flag_France" title="French" href="<?php echo $basename_with_uid; ?>&lang=fr"><img src="css/images/fr.png"></a>
REQUEST_URI is probably what you are after:
<a class="flag_France" title="French" href="<?php echo $_SERVER['REQUEST_URI']; ?>&lang=fr"><img src="css/images/fr.png"></a>
If your page was profile.php?uid=12, the output should be:
profile.php?uid=12&lang=fr
Ref: PHP $_SERVER variables
edit You may still need to add basename() around REQUEST_URI, depending on what you are doing

get file name for url php

I wanted to know how to get the current file name in PHP to be able to load the same file in a different directory.
index.php
works.php
lang/de/
index.php
works.php
lang/pl/
index.php
works.php
<div id="language">
EN
<a class="lang" href="index.php">DE</a>
<a class="lang" href="../pl/index.php">PL</a>
</div>
The current method is redirecting the lang URL, allways to index.php.
I would love to know how to redirect from works.php to lang/de/works.php without redirecting to lang/de/index.php
Sorry if i'm getting you confused
I think this is what you want:
<?php
$page = basename($_SERVER['PHP_SELF']);
?>
<div id="language">
EN
<a class="lang" href="<?php echo $page;?>">DE</a>
<a class="lang" href="../pl/<?php echo $page;?>">PL</a>
</div>
You would save the current file name in the $page variable. Then echo it out and replace index.php in your links.
You should really google this stuff.
<?php basename($_SERVER['PHP_SELF']); ?>
GOOGLE
Now that you added some code, here ya go.
<div id="language">
EN
<a class="lang" href="<?php echo basename($_SERVER['PHP_SELF']); ?>">DE</a>
<a class="lang" href="../pl/<?php echo basename($_SERVER['PHP_SELF']); ?>">PL</a>
</div>
FYI, basename($_SERVER['PHP_SELF']); get's the name of the current file and returns just that. In other words, it will return "index.php" or "works.php"

CodeIgniter - Correct way to link to another page in a view

I was wondering if someone could tell me the correct way to link to another page from within a view.
Is there a function for this or is it just the usual about
I assume you are meaning "internally" within your application.
you can create your own <a> tag and insert a URL in the href like this
Link
OR you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
and that will generate
Link
For the additional commented question
I would use my first example
so...
<img src="<?php echo base_url() ?>img/path/file.jpg" />
for images (and other assets) I wouldn't put the file path within the PHP, I would just echo the base_url() and then add the path normally.
The best way is to use the following code:
Link
you can also use PHP short tag to make it shorter. here's an example
<a href="<?= site_url('controller/function'); ?>Contacts</a>
or use the built in anchor function of CI.
Best and easiest way is to use anchor tag in CodeIgniter like eg.
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
Refer https://www.codeigniter.com/user_guide/helpers/url_helper.html for details
This will surely work.
you can also use this code
//test" class="btn btn-primary pull-right">
<a href="<?php echo site_url('controller/function'); ?>Compose</a>
<a href="<?php echo site_url('controller/function'); ?>Inbox</a>
<a href="<?php echo site_url('controller/function'); ?>Outbox</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>

Why won't my PHP variable appear in the HREF in my CakePHP view?

In my CakePHP code I have the following code. If i click on the image delete it moves to the link in href. In the href I dont know how to display my php value. I tried it like below But it didn't work.
<a href="http://localhost/cake_1.2.1.8004/index.php/forms/delete/"<?php echo $r['Form']['id'];?> >
<img border="0" alt="Delete" src="/cake_1.2.1.8004/app/webroot/img/delete.png"/>
</a>
Any suggestions?
use cakephp view helpers:
<?php
echo $html->link(
$html->image('delete.png'),
array('action'=>'delete', $r['Form']['id']),
array(),
'really delete?',
false
);
?>
Put your echo in your quotes:
<a href="http://localhost/cake_1.2.1.8004/index.php/forms/delete/<?php echo $r['Form']['id'];?>">
<img border="0" alt="Delete" src="/cake_1.2.1.8004/app/webroot/img/delete.png"/>
</a>

Categories