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

#11
(03-25-2016, 03:05 AM)richie41 Wrote:
(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

Maybe you should try other tutorials. Those that are made for beginners...
Reply

#12
(03-25-2016, 03:21 AM)Avenirer Wrote:
(03-25-2016, 03:05 AM)richie41 Wrote:
(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

Maybe you should try other tutorials. Those that are made for beginners...
I've followed this project through about 5 or more videos. I'm not giving up now
Reply

#13
It may be confusing, but don't use capital letters in your hyperlinks or controller/function calls. Although the file names must be first-caps, CI will recognize which controller/function to call.
Is the details page not giving any error message anymore?

Please try this:

PHP Code:
public function details($id)
{
   
//Get Product Details
   
$data['product'] = $this->product_model->get_product_details($id);

   echo 
'<pre>';
   
print_r($data);
   echo 
'</pre>';

   
//Load View
  
$data['main_content'] = 'details';
  
//$this->load->view('layouts/main', $data);



This should output the contents of your $data array, including the object or array that was returnd by your model.
Reply

#14
(03-25-2016, 03:23 AM)Wouter60 Wrote: It may be confusing, but don't use capital letters in your hyperlinks or controller/function calls. Although the file names must be first-caps, CI will recognize which controller/function to call.
Is the details page not giving any error message anymore?

Please try this:

PHP Code:
public function details($id)
{
 
  //Get Product Details
 
  $data['product'] = $this->product_model->get_product_details($id);

 
  echo '<pre>';
 
  print_r($data);
 
  echo '</pre>';

 
  //Load View
 
 $data['main_content'] = 'details';
 
 //$this->load->view('layouts/main', $data);



This should output the contents of your $data array, including the object or array that was returnd by your model.

Just changed the link in products.php file in the VIEW folder to products/details/ then put your above code in the Products.php file in the CONTROLLERS folder. There is no error but it doesn't take me to the details page. It stay on the same page. It is supposed to load the details of a single game with a description and a photo. I have a header.php and a footer.php that's and then the details.php is supposed to lload in place of all the games. So it goes localhost/gamingplace then when you clikc on the link it supposed to load the details of the game you clicked on so it would be localhost/gamingplace/products(in the controller folder Products.php)/details(load the details function in the controllers folder Products.php)/1(id number of game pulled from database) Oh and by the way what does CI stand for. Also thanks for the help
Reply

#15
Try this and see if it works, if not you have other problems in your code.

This is just a test link to see if it works:

PHP Code:
<?php echo site_url("products/details/1"); ?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#16
(03-25-2016, 03:54 AM)InsiteFX Wrote: Try this and see if it works, if not you have other problems in your code.

This is just a test link to see if it works:

PHP Code:
<?php echo site_url("products/details/1"); ?>

Tried that. And it still just stays on the same page with all the products instead of going to the details page of a single product. So I need to just try it with a normal page that doesn't pull in the header and footer and main content and just try static pages
Reply

#17
(03-25-2016, 03:23 AM)Wouter60 Wrote: Please try this:

PHP Code:
public function details($id)
{
 
  //Get Product Details
 
  $data['product'] = $this->product_model->get_product_details($id);

 
  echo '<pre>';
 
  print_r($data);
 
  echo '</pre>';

 
  //Load View
 
 $data['main_content'] = 'details';
 
 //$this->load->view('layouts/main', $data);



This should output the contents of your $data array, including the object or array that was returnd by your model.

@richie41: What output you get when run above function?
Reply

#18
(03-25-2016, 05:46 AM)pdthinh Wrote:
(03-25-2016, 03:23 AM)Wouter60 Wrote: Please try this:

PHP Code:
public function details($id)
{
 
  //Get Product Details
 
  $data['product'] = $this->product_model->get_product_details($id);

 
  echo '<pre>';
 
  print_r($data);
 
  echo '</pre>';

 
  //Load View
 
 $data['main_content'] = 'details';
 
 //$this->load->view('layouts/main', $data);



This should output the contents of your $data array, including the object or array that was returnd by your model.

@richie41: What output you get when run above function?










PHP Code:
class Products extends CI_Controller{
    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);
    }

Sure I've tried that. I just commented out the get all products in the Products.php in the CONTROLLERS folder. So it just left the get product.
PHP Code:
$route['default_controller'] = 'products/details'


Changed the routes.php to 'products/details'.

Took out all the php from details.php file in the VIEWS folder. And the details page loads.

So the routes.php needs to be configured to show the get all products when the url is localhost/thegamingplace then when I click on one of the products the url should be localhost/thegamingpace/products/details/(whatever the id is) and should display the single product details.php page
Reply

#19
Your product id needs to be passed to the controller from the view link.

It sounds like you are not passing the id to the controller,
you can check the in the details method by doing a echo $id; exit;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#20
(03-25-2016, 12:59 PM)InsiteFX Wrote: Your product id needs to be passed to the controller from the view link.

It sounds like you are not passing the id to the controller,
you can check the in the details method by doing a echo $id; exit;

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

if I put the just put <a href="<?php echo $product->id; ?>"> as the link then it shows the correct id in the URL
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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