S
S
sllugovskih2017-02-25 16:39:08
CodeIgniter
sllugovskih, 2017-02-25 16:39:08

Cities in URL CodeIgniter how?

It is necessary that the site has a URL instead of site.ru /city/ moskva/kvartiry/sdam/ of the form: site.ru/moskva/kvartiry/sdam
All parameters must be "dynamic" in the address.
There is a City controller code below:

class City extends CI_Controller {

  public function index($param1, $param2) {
    
    if ($param1 == 'kvartiry') {
      echo "страница квартир";
    }
    
    if ($param2 == 'sdam') {
      echo "тип сделки: Сдача";
    }
    
  }

}

It turned out to render the site in the site.ru/moskva/ format via routes.php by adding the line: This triggers the index method in the City controller. But how to make additional parameters also accepted? for example site.ru/moskva/kvartiry/ - already gives a 404 error. I tried adding a line to routes.php: didn't help
$route['(:any)'] = "city";
$route['(:any)'] = "city/$1";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrKMV34, 2017-02-25
@MrKMV34

Alternatively, you can specify the maximum number of parameters that will fall into the action of the controller
And process them as needed.

class Сity extends CI_Controller
{
   
    public function index($city = 'msk', $object = '', $offer_type = '')
    {
        echo '<pre>' . var_export($city, true) . '</pre>';
        echo '<pre>' . var_export($object, true) . '</pre>';
        echo '<pre>' . var_export($offer_type, true) . '</pre>';
        die;
    }
}

0
0xD34F, 2017-11-07
@DrunkMaster

<div class="wrapper">
  <div class="item"></div>
  <div class="item"></div>
</div>

.wrapper {
  display: flex;
  justify-content: space-evenly;
  border: 1px solid black;
  height: 200px;
}

.wrapper .item {
  border: 1px solid black;
  width: 40%;
  height: 20%;
  position: relative;
  top: 70%;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question