Welcome Guest, Not a member yet? Register   Sign In
Rewrite on name
#1

[eluser]iniweb[/eluser]
I'am very interesting how work controller on: http://codeigniter.com/news/ and this rewrite: http://codeigniter.com/news/codeigniter_154_released/

Please show me controller ):
#2

[eluser]xwero[/eluser]
The http://codeigniter.com/news/ you can accomplish by .htaccess and using routing

the title of the news can be made url friendly using the url helper function url_title

hope this helps
#3

[eluser]iniweb[/eluser]
routes.php:

Code:
$route['default_controller'] = "main";
$route['scaffolding_trigger'] = "";

$route['News/:num'] = "News/News_lookup";

news.php (Cotroller):

Code:
class News extends Controller {

    function News()
    {
        parent::Controller();    
    }
    
    function Index()
    {
        $content = '';

        $content .= $this->uri->segment('1');

        $data = array(
                       'content'  => $content,
                 );

        $this->parser->parse('Empty.tpl', $data);
    }

    function News_lookup()
    {

        echo 'News loockup';

    }
}

http://example.com/news/title/

404 Page Not Found

What further?
#4

[eluser]xwero[/eluser]
The page is not found because you use title and in your route you added the wildcard :num that is why you get a 404 error. http://example.com/news/1/ would lead you to the News_lookup function of your class.

What you want to do is

Code:
// router
$route['news/([a-zA-Z1-9_-]+)'] = "News/News_lookup/$1";
// controller
function News_lookup()
{
   echo $this->uri->rsegment(3);
}

If you have the url http://example.com/news/title/ you should get a page with the word title
#5

[eluser]iniweb[/eluser]
Very big thx!




Theme © iAndrew 2016 - Forum software by © MyBB