Welcome Guest, Not a member yet? Register   Sign In
can't get link to work
#21

Have you tried loading the url helper in your controller (before it loads the view from you index function)?
Then, in the view, put the following code:
PHP Code:
<?php echo anchor('products/details/' $product->id$product->name);?>

The url helper will include your base_url path.
Reply
#22

(03-26-2016, 01:20 AM)Wouter60 Wrote: Have you tried loading the url helper in your controller (before it loads the view from you index function)?
Then, in the view, put the following code:
PHP Code:
<?php echo anchor('products/details/' $product->id$product->name);?>

The url helper will include your base_url path.

PHP Code:
<?php
class Products extends CI_Controller{
2    public function index(){
3        //Get All Products
4        $data['products'] = $this->Product_model->get_products();
5        //Load View
6        $data['main_content'] = 'products';
7        $this->load->view('layouts/main'$data);
8    }
9
10        
11
12    
public function details($id){
13        //Get Product Details
14        $data['product'] = $this->Product_model->get_product_details($id);
15        //Load View
16        $data['main_content'] = 'details';
17        $this->load->view('layouts/main'$data);
18    }
}

Where in the above do I put the url helper
Reply
#23

Post your details view code here so we can look at it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#24

(03-26-2016, 03:33 AM)InsiteFX Wrote: Post your details view code here so we can look at it.

PHP Code:
<div class="row details">
 
 <div class="col-md-4">
 
 <img src="<?php echo base_url(); ?>assets/images/products/<?php echo $product->image; ?>" />                
  
</div>
 
 <div class="col-md-8">
 
   <h3><?php echo $product->title?></h3>
    <div class="details-price"><?php echo $product->price?></div>
    <div class="details-description"><p><?php echo $product->description?></p></div>

    <div class="details-buy">
      <form method="post" action="<?php echo base_url(); ?>cart/add<php echo $product->id; ?>">
      QTY: <input class="qty" type="text" name="qty" value="1" /><br>
      <input type="hidden" name="item_number" value="<?php echo $product->id?>"></input>
      <input type="hidden" name="price" value="<?php echo $product->price?>"></input>
      <input type="hidden" name="title" value="<?php echo $product->title?>"></input>
      <button class="btn btn-primary" type="submit">Add To Cart</button>
      </form>
    </div>
  </div>
</div> 
Reply
#25

Like I said: in the index function:

PHP Code:
public function index(){
 
   //Get All Products
 
   $this->load->helper('url');
 
   $data['products'] = $this->Product_model->get_products();
 
   //Load View
 
   $data['main_content'] = 'products';
 
   $this->load->view('layouts/main'$data);

Now, in your 'products' view, you can use the anchor() function to build the link.
Reply
#26

(This post was last modified: 03-26-2016, 03:58 AM by richie41.)

(03-26-2016, 03:43 AM)Wouter60 Wrote: Like I said: in the index function:

PHP Code:
public function index(){
 
   //Get All Products
 
   $this->load->helper('url');
 
   $data['products'] = $this->Product_model->get_products();
 
   //Load View
 
   $data['main_content'] = 'products';
 
   $this->load->view('layouts/main'$data);

Now, in your 'products' view, you can use the anchor() function to build the link.

Just done that and now when I click on the link I get:


Access forbidden! You don't have permission to access the requested object. ERROR 403. My routes.php look like this:
PHP Code:
//$route['(:any)'] = 'products/details';
$route['default_controller'] = 'products';

$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE
Reply
#27

Check your config.phg file in application/config.
Does it have a value for $config['index_page'] ?
If you let .htaccess skip the index.php part of your URL's, you must leave it blank in config.php:
$config['index_page'] = '';
Reply
#28

(03-26-2016, 04:51 AM)Wouter60 Wrote: Check your config.phg file in application/config.
Does it have a value for $config['index_page'] ?
If you let .htaccess skip the index.php part of your URL's, you must leave it blank in config.php:
$config['index_page'] = '';

Yes it is left blank in the $config['index_page'] = "";
My .htaccess file is in the root and looks like the following:
PHP Code:
Options +FollowSymLinks
Options 
-Indexes
DirectoryIndex index
.php
RewriteEngine on
RewriteCond 
$!^(index\.php|layouts|assets|css|js|images|products|robots\.txt|favicon\.ico)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond 
%(REQUEST_FILENAME) !-d
RewriteRule 
^(.*) index.php?/$[L,QSA
Reply
#29

(This post was last modified: 03-26-2016, 06:02 AM by Wouter60.)

If you have a folder named "products" in the root of your website, then url routing will fail because the folder has the same name as your Products controller.
Please try to rename this folder to "product_catalog".
Reply
#30

(This post was last modified: 03-26-2016, 06:32 AM by richie41.)

(03-26-2016, 06:02 AM)Wouter60 Wrote: If you have a folder named "products" in the root of your website, then url routing will fail because the folder has the same name as your Products controller.
Please try to rename this folder to "product_catalog".

The products folder is not in the root. I have renamed it anyway to productscat and updated the .htaccess and the products.php file in the VIEWs folder. Still getting the Access Forbidden! Error 403. The link on the products page at http://localhost/thegamingplace is showing as http://localhost/thegamingplace/?products/details/1"> above the photos. When I change the link in products.php in the Views folder back to the original
     
PHP Code:
<a href="<?php echo base_url(); ?>products/details/<?php echo $product->id; ?>">
 <
img src="<?php echo base_url(); ?>assets/images/productscat/<?php echo $product->image; ?>" /></a

then when I click on the link it shows the correct url http://localhost/thegamingplace/products/details/1 and doesn't give me the ERROR 403 BUT doesn't show the details page it just stays at the products page. When I use the f12 inspect element in the browser it shows the correct link for each product. It's just not loading the details page in place of the products page.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB