Welcome Guest, Not a member yet? Register   Sign In
remove parameter from url
#1

[eluser]fdqepd[/eluser]
Hi, i have a website with a bunch of static pages, so i made a controller that takes care of them
Code:
<?php
class page extends Controller {

    function page()
    {
        parent::Controller();    
    }
    
    function loadPage($name, $title)
    {    
        
        $data['head_title'] = $title;
        
        
        $this->load->view('header', $data);
        $this->load->view('pages/'.$name.'.html');
        $this->load->view('footer', $data);
        
        
    }

}
?>

i send the title in the url as a parameter like this
Code:
href="/filename/title"

it works just fine, but i cant figure out how to de the following:

i want my url to be 'www.site.com/title' instead of 'www.site.com/filename/title',
also i need to deal with special charactes like á, ñ, etc in the title.

can anybody help me out?

thanks
#2

[eluser]kyleect[/eluser]
Use routes. Also, I created a controller for this as well. Here is mine in case you want to use it:

Set the route like this:

Code:
$routes['static_page'] = 'pages/static_page';

so http://localhost/static_page loads http://localhost/pages/static_page

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

/**
* Pages
*
* Displays static views not associated with another controller.
*
* Routing is still required for this: http://localhost/static_page
* The routing will look like this:
*      $routes['static_page'] = 'pages/static_page';
*
* The views for these static pages are located: Application/Views/Pages
*
* TODO for version 0.02:
*      - Figure out how to rid the requirements of routes
*      - add support for directories indicated by url segments
*
* @package CI1.7_kyct
* @subpackage pages
* @category controllers
* @author Kylee Tilley <[email protected]>
* @version 0.01
*/

// ------------------------------------------------------------------------

/**
* Controller: Pages
*
* Displays static views not associated with another controller.
*
* @package CI1.7_kyct
* @subpackage pages
* @category controllers
**/

    class Pages extends Controller {
    
        /**
         * name
         *
         * The name of the view being loaded
         *
         * @var string
         **/
        
        private $name;
        
        /**
         * path
         *
         * The server path to the view file being loaded
         *
         * @var string
         **/
        
        private $path;
        
        /**
         * view
         *
         * The segment path of the view being loaded
         *
         * @var string
         **/
        
        private $view;

        function __construct()
        {
            parent::__construct();
        
            $this->name = $this->uri->segment(1);
            $this->path = APPPATH.'views/pages/'.$this->name.'.php';
            $this->view = 'pages/'.$this->name;
        }

        private function index(){}
        
        /**
         * _remap
         *
         * _remap overrides normal MVC behavior by not automatically running the method being requested.
         * This is being used to avoid needing a method to display the pages.
         *
         * @return void
         **/
        
        function _remap($method)
        {
            if(method_exists($this, $method))
            {
                log_message('debug', 'Controller: Pages: _remap: Method "'.$method.'" is defined; Returning to default behavior');
                $this->$method();
            }
            else
            {
                if(file_exists($this->path))
                {
                    log_message('debug', 'Controller: Pages: _remap: "'.$this->path.'" found. Loading view: "'.$this->view.'"');
                    $this->load->view($this->view);
                }
                else
                {
                    log_message('error', 'Controller: Pages: _remap: "'.$this->path.'" not found. but file could not be located. Sending error code 404 to the browser');
                    show_404();
                }
            }    
        }
    }
?&gt;
#3

[eluser]fdqepd[/eluser]
Ive managed to set nice ulrs with url_title()
using it like this
Code:
<a href="/grupo/&lt;?= url_title('Ladrón que roba a ladrón'); ?&gt;">

but y want it tho display with special characters in the title...

clean for the url but ugly for titles, how can i accompllish that?
#4

[eluser]fdqepd[/eluser]
@kyleect
thanks! i will try your controller and see what happens

bye




Theme © iAndrew 2016 - Forum software by © MyBB