First problem:
Main url: site-test
1. I clicked on the link <a href="tasks/">tasks</a>
-> url: site-test/tasks
2. i click next link <a href="tasks/page/2">next page</a>
(Where "tasks" - contoller, "page" - action, "2" - action value) -> url: site-test/tasks/page/2
3. i pressed again <a href="tasks/">tasks</a>
and url -> site-test/tasks/page/tasks instead site-test/tasks/ what i need.
<a href="tasks/">tasks</a>
is located in template view.
Second problem:
When url is: site-test or site-test/tasks all files loading from root_directory/images or root_directory/css, when url is: site-test/tasks/page/2 he tries to find these files in root_directory/tasks/page/images
My route:
static function start()
{
$controller_name = 'add_task';
$action_name = 'index';
$routes = explode('/', $_SERVER['REQUEST_URI']);
if ( !empty($routes[1]) )
{
$controller_name = $routes[1];
}
if ( !empty($routes[2]) )
{
$action_name = $routes[2];
}
$model_name = 'Model_'.$controller_name;
$controller_name = 'Controller_'.$controller_name;
$action_name = 'action_'.$action_name;
$model_file = strtolower($model_name).'.php';
$model_path = "application/models/".$model_file;
if(file_exists($model_path))
{
include "application/models/".$model_file;
}
$controller_file = strtolower($controller_name).'.php';
$controller_path = "application/controllers/".$controller_file;
if(file_exists($controller_path))
{
include "application/controllers/".$controller_file;
}
$controller = new $controller_name;
$action = $action_name;
if(method_exists($controller, $action))
{
if ( !empty($routes[3]) )
{
$controller->$action($routes[3]);
}
else{
$controller->$action();
}
}
}
My controller:
class Controller_tasks extends Controller
{
function __construct()
{
$this->model = new Model_tasks();
$this->view = new View();
}
function action_index()
{
$data = $this->model->get_data_from_server();
$this->view->generate('tasks_view.php', 'template_view.php', $data);
}
function action_page($page = 1)
{
var_dump($page);
$data = $this->model->get_data_from_server($page);
$this->view->generate('tasks_view.php', 'template_view.php', $data);
}
}
Thx for any help, coz im rly confused.