D
D
dk-web2015-09-28 01:02:44
PHP
dk-web, 2015-09-28 01:02:44

How to get parameters when parsing url (php, mvc, ajax)?

There is an app.php file Shortened
version...

class App
{
  protected $controller = 'Main_controller';
  protected $method = 'index';
  protected $params = [];
  const SITE_PATH = '/mysiteru/public/';

  public function __construct (){
  $url = $this->parseUrl();
        unset($url[0]);
        unset($url[1]); (убираю контроллер и метод базовый)
    $this->params = $url ? array_values($url) : [];
    // BASE::print_data($this->params);
    call_user_func_array([$this->controller,$this->method],$this->params);
  }
  public function parseUrl (){
    if(isset($_GET['url']))
    {
      return $url=explode('/',filter_var(rtrim($_GET['url'],'/'),FILTER_SANITIZE_URL));
    }
  }
}


I call
new App();

Now the crux of the matter...
there is an ajax request to the mo_search controller

$('form').on('change','select',function(){
   $.ajax({
        type: "POST",
        url: "/mysiteru/public/mo_search/chained/5/need/",
        dataType: "json",
        success: function(data, textStatus) {
            console.log(data);
        }
    }); /// КОНЕЦ AJAX
});


In mo_search controller

public function chained($params)
  {
    $url=App::parseUrl(); //работает
    $url=App::$this->params; // не работает..
  }


How to get parameter array from App? Or do you need to parse again? but after all the controler and a method is defined correctly... how to take away parameters?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Santiago K, 2015-09-28
@allexp

Add a get_params() method to the App for example.

S
Sergey Zelensky, 2015-09-28
@SergeyZelensky-Rostov

And why not do this: ajax calls you with such an address sample/search we
launch the sample controller and call the search method, which either processes the POST itself (which is not very good), or passes it to the model that checks the POST data and does its dirty deeds with them
For example, I have a POST data check based on the fact that a specific one is accessed, like this, for example,
Requst::checkVarPost('search','string');why not use only POST for such things?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question