CodeIgniter Forums
How i can executed my controller in the url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: How i can executed my controller in the url (/showthread.php?tid=69522)



How i can executed my controller in the url - Stef - 12-08-2017

Hey,

i have choosing today the way to coding with CodeIgniter. So i'm a newbie in frameworks, but the framework looks not so hard. I have tried the first Tutorial "static page". Now if i want to call the site in the url i get everytime the error, that this site doesn't exist. I don't know why this is. 

A url looks after the tutorialsite so : /[controller-method]/[arguments]http://example.com/[controller-class]/[controller-method]/[arguments]

I executed all at xampp local. And if i executed it like this i get everytime the error.

My Path to the framework folder is this :http://localhost/php/frameworks/codeigniter/
Now if i want to executing my controller with the method the url must be like this: http://localhost/php/frameworks/codeigniter/pages/view

But if i load this url i get everytime the error, that this object can't get found.

The Code is:


PHP Code:
<?php

class Pages extends CI_Controller{

    public function 
view($page 'header'){

        
// APPPATH = application folder

        
if(!file_exists(APPPATH "views/templates/" $page ".php")){
            
show_404(); // ->shows 404 error site
        
}

        
$data = [];

        
$data["title"] = ucfirst($page); // ucfirst sorgt dafür das der erste buchstabe ein Großbuchstabe ist


        //seite laden/aufrufen
        
$this->load->view("pages/header/"$data);
        
$this->load->view("pages/footer/"$data);

    }



My 2 view-datas looks so:

header.php
PHP Code:
<!DOCTYPE html>
    <
html>
        <
head>
            <
title><? echo $title?></title>
        </head>
        <body>
            <p>Titel dieser Seite lautet <? echo $title; ?></p> 

footer.php
PHP Code:
        <p>copyright @stef</p>

    </
body>
</
html

Hope you can help me.

Stef


RE: How i can executed my controller in the url - Stef - 12-09-2017

I have solved id. The problem was the missing routes.


RE: How i can executed my controller in the url - InsiteFX - 12-09-2017

Did you setup your base_url in the config.php file?
Did you setup your routes in the routes.php file?