Welcome Guest, Not a member yet? Register   Sign In
regarding URLs / Titles
#3

(10-28-2015, 12:57 PM)mwhitney Wrote: The docs: http://www.codeigniter.com/docs
Some high points, assuming you're using CI3:
- Overview: http://www.codeigniter.com/user_guide/ov...index.html
- Tutorial: http://www.codeigniter.com/user_guide/tu...index.html
- CodeIgniter URLs: http://www.codeigniter.com/user_guide/general/urls.html
- URI Routing: http://www.codeigniter.com/user_guide/ge...uting.html
- Controllers: http://www.codeigniter.com/user_guide/ge...llers.html

More than likely, index.php/inventory/detail/69 is routing to a controller named Inventory and passing 69 to a method named detail(). The best way to change this to handle a URL like "www.blahblahblah.com/index.php/inventory/detail/1959-rolls-royce-phantom" would be to start with the detail() method.

More than likely the number is going to be a key value, and the detail() method will load a model and call a method on the model to look up the details of the car based on that key. Take a look at the model and determine whether it already has a method to look up the details based on the vehicle's title in the form you will be able to use in the URL. If it does, this is going to be an easy process. I would most likely attempt to retrieve the vehicle by title given the input. If that fails and the input is numeric, attempt to look it up by key. If the key lookup succeeds, I would grab the title from the returned data and redirect to the titular form of the URL, or use it to supply a canonical URL for SEO.

If the model doesn't have a method to look up the vehicle by title, or the titles in the database aren't suitable for use in a URL, you will probably need to modify the model to provide that functionality. You may also decide to modify the database to add a column to store URL-friendly titles to make the lookup process easier.

wow, thank you so much for your help with this - I have unfortunately got called on to perform other duties today (I essentially handle all IT/Tech duties for the company), but I am going to take a look at this tonight from home.

In the meantime, here is the "details" controller / page code for each vehicle:

Code:
<?php $this->load->view('_inc/_head'); ?>

<div id="detail" class="grid_10 push_1">

<h1><?php echo $record->production_year . " " . $record->make . " "  . $record->model; ?></h1>

<?php
$spec_keys = array(
'stock',
'current_condition',
'performance',
'performance_options',
'transmission',
'suspension',
'color_exterior',
'color_interior',
'features',
'options',
'optional_equipment',
'mileage',
'wheels',
'tires',
'brakes',
'vin_num',
'engine_num',
'gearbox_num',
'other_1',
'other_2',
'other_3'
);
?>

<table title="Specifications" class="grid_6 alpha">
<tr>
<td><h5>Specifications</h5></td>
</tr>
<?php foreach ($spec_keys as $k) : if($record->$k != "") : ?>
<tr>
<td><?php echo ucfirst(str_replace('num', '#', str_replace('_', ' ', $k))); ?>:</td>
<td><?php echo $record->$k; ?></td>
</tr>
<?php endif; endforeach; ?>
</table>


<img class="grid_4 omega" src="<?php echo base_url(); ?>/gallery/<?php echo $record->stock . "/" . $record->stock; ?>.jpg" />
<div class="clear"></div>


<ul class="buttons">
<li><?php echo anchor('inventory/index','« Back',''); ?></li>
<li><?php echo anchor("contact/buyer/$record->id",'Serious Buyer','class="pop_form"'); ?></li>
<li><?php echo anchor("contact/inquire/$record->id",'Inquire','class="pop_form"'); ?></li>
<li><?php echo anchor(base_url() . "gallery/" . $record->stock,'View Gallery','target="_blank"'); ?></li>
<?php
$video_formats = array(
'wmv',
'mov',
'mpg',
'mp4'
);
$video_found   = false;
$video_name    = "gallery/" . $record->stock . "/" .$record->stock . "-vid";

foreach ($video_formats as $format) {
   $file = $video_name . "." . $format;
if (file_exists("$file")) {
echo '<li><a href="' . base_url() . $file . '" class="pop_video">Video</a></li>' . "\n";
break;
}
}
?>
</li>
</ul>


<div class="clear"></div>

<h5>Description</h5>
<p><?php echo $record->description; ?></p>
<h5>History</h5>
<p><?php echo $record->history; ?></p>
<?php
 $image_formats = array(
  'jpg',
  'JPG',
  'gif',
  'png'
 );
 $auth_found     = false;
 $file_name = "gallery/" . $record->stock . "/" .$record->stock . "-auth";

 foreach ($image_formats as $format) {
     $file = $file_name . "." . $format;
  if (file_exists("$file")) {
       $str  = "";
       $str .= "<h5>Authenticity</h5>\n";
  $str .= '<p><img src="' . base_url() . $file . '" width="300" /></p>' . "\n";
  echo $str;
  break;
  }
}?>
<?php

/*

echo $record->restoration_candidate;
echo $record->authenticity_url;

*/
?>

</div><!-- eo #detail -->
<?php $this->load->view('_inc/_foot'); ?>

and here is the "inventory" controller/page code:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inventory extends CI_Controller {

 function __construct() {
   parent::__construct();
   $this->load->model('inventory_model');
 }

 public function index() {
   $data = array();

   if($query = $this->inventory_model->get_inventory()) {
     $data['records'] = $query;
     $data['makes']   = $this->inventory_model->get_makes();
   }
   $this->load->view('inventory/index_page', $data);
 }

public function make() {
$data  = array();
$query = "";
$make  = urldecode($this->uri->segment(3));

$query = ($make) ? $this->inventory_model->get_records_of_make() : "";


if($query) {
$data['records'] = $query;
$data['makes']   = $this->inventory_model->get_makes();
$this->load->view('inventory/index_page', $data);
} else {
redirect('inventory');
}

}

public function archived() {
$query = $this->inventory_model->get_archived();

if($query) {
$data['records'] = $query;
$data['makes']   = $this->inventory_model->get_makes();
$this->load->view('inventory/index_page', $data);
} else {
redirect('inventory');
}

}

 public function detail() {
   $data['record'] = $this->inventory_model->get_record();
   $this->load->view('inventory/detail_page', $data);
 }

}

?>


Many many thanks once again and I'll see what I can accomplish later this evening. The other thing that has been a debacle to get going is a recaptcha on the details page inquiry form, but that 's likely my just incompetence with CI  Confused
Reply


Messages In This Thread
regarding URLs / Titles - by lc317 - 10-28-2015, 10:59 AM
RE: regarding URLs / Titles - by mwhitney - 10-28-2015, 12:57 PM
RE: regarding URLs / Titles - by lc317 - 10-28-2015, 04:01 PM
RE: regarding URLs / Titles - by lc317 - 10-29-2015, 11:26 AM
RE: regarding URLs / Titles - by mwhitney - 10-29-2015, 12:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB