• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can't get link to work

#1
Hi,

I've been following a youtube video on creating a website with the use of codeigniter. The video is PHP and MySQL Get and Display Products - 6 -41.

I've followed the video so far but have got stuck.

So far the video has shown me how to load xampp on to my windows 10 machine; copy the codeigniter folder over to hdocs; create a database with mysql; create a page that pulls in header, product content, and footer; pull the product information from the database to display it on the main page. The main page is localhost/thegamingplace

I have got stuck trying to get a link to display another page. This link on the main page is:

<a href="<?php echo base_url(); ?>products/details/<?php echo $product->id; ?>">

So it goes to the main page which i have set in the config.php file to $config['base_url'] = 'http://localhost/thegamingplace/';

Then it supposed to go to the products controller and then call the details function and display the details.
In routes.php it is set to: $route['default_controller'] = 'products';

I have a file called products.php in the controllers folder that looks like this:
<?php
class Products extends CI_Controller{
 public function index(){
  //Get All Products
  $data['products'] = $this->Product_model->get_products();
  //Load View
     $data['main_content'] = 'products';
  $this->load->view('layouts/main', $data);
 }

 public function details($id){
  //Get Product Details
  $data['product'] = $this->Product_model->get_product_details($id);
  //Load View
  $data['main_content'] = 'details';
  $this->load->view('layouts/main', $data);
 }
}

When I click on the link i get: http://localhost/thegamingplace/products/details/1
But with an error message:Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.19
 
I've followed the video exactly and rewatched it about 5 times now. In the video it works for him. If anyone could help it would be very much appreciated.
Reply

#2
PHP Code:
<?php echo site_url("products/details/".$product->id); ?>

http://www.codeigniter.com/user_guide/he...l#site_url

pls use [php] tags in the board.

Have you config a .htaccess file?
http://www.codeigniter.com/user_guide/ge...x-php-file
Reply

#3
Did you use a capitalized filename for the controller?  Products.php
CI 3.1 Kubuntu 19.04 Apache 5.x&nbsp; Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply

#4
(03-24-2016, 02:30 PM)twpmarketing Wrote: Did you use a capitalized filename for the controller?  Products.php

no
Reply

#5
no I didn't use capitalized filename for the controller
Reply

#6
(03-24-2016, 12:26 PM)Paradinight Wrote:
PHP Code:
<?php echo site_url("products/details/".$product->id); ?>

http://www.codeigniter.com/user_guide/he...l#site_url

pls use [php] tags in the board.

Have you config a .htaccess file?
http://www.codeigniter.com/user_guide/ge...x-php-file

I have the url helper set in autoload. I have the .htcaccess set as per documents. I have enable_query_strings set to TRUE. I put in the php code you supplied and even though it doesn't load the details page it doesn't give the error message so looks promising.
Reply

#7
Normally you access loaded models with lower-case name. Let's give it a try.
PHP Code:
//Get All Products
 
 $data['products'] = $this->product_model->get_products();

//Get Product Details
 
 $data['product'] = $this->product_model->get_product_details($id); 
Reply

#8
(03-24-2016, 07:01 PM)pdthinh Wrote: Normally you access loaded models with lower-case name. Let's give it a try.
PHP Code:
//Get All Products
 
 $data['products'] = $this->product_model->get_products();

//Get Product Details
 
 $data['product'] = $this->product_model->get_product_details($id); 

Hi just tried the above and with: $autoload['model'] = array('product_model'); set in autoload.php. Changed the file name to product_model.php in the MODELS folder. Changed it to your above PHP code in the products.php file in the CONTROLLERS folder. Tried in the products.php file in the VIEW folder with the link set like shown in the video:
<a href="<?php echo base_url(); ?>products/details/<?php echo product->id; ?>"> and the way show in the other reply above. And still not loading the details page. It is supposed to load the details page but there is something about the link that is wrong or something is stopping it from loading the details page.
Reply

#9
Be sure to name all controllers, libraries and models with a first capital letter.
So your Products controller must be named "Products.php", not "products.php".
Reply

#10
(03-25-2016, 02:54 AM)Wouter60 Wrote: Be sure to name all controllers, libraries and models with a first capital letter.
So your Products controller must be named "Products.php", not "products.php".

I changed the products.php to Products.php file in the CONTROLLERS folder. The MODEL folder has a file Product_model.php. But still will not load the details page from the link. Changed the link from products/details/ to Products/details/. Still not working. I've attached the product.php file that is in the VIEW folder where the link is that is supposed to open the details page


Attached Files
.php   products.php (Size: 997 bytes / Downloads: 131)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.