Welcome Guest, Not a member yet? Register   Sign In
Codeigniter METHOD ??? -error ?
#1

[eluser]sarah fox[/eluser]
Hi,

Looking at :- http://ellislab.com/codeigniter/user-guide/ - I see controllers, models, views. helpers etc..

But nothing about METHODS .

I've done a debug of my scripts & THINK I found a problem as to why CI doesn't work on my WIN XP box.

C:\usr\local\lib\codeigniter\current\system\codeigniter\CodeIgniter.php

Code:
echo "if ( ! class_exists($class)<BR>
    OR $method == 'controller'<BR>
    OR strncmp($method, '_', 1) == 0<BR>
    OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))<BR>
\n";

echo "<B>
if ( ! class_exists(".$class.")<BR>
    OR ".$method." == 'controller'<BR>
    OR strncmp(".$method.", '_', 1) == 0<BR>
    OR in_array(strtolower(".$method."), array_map('strtolower', get_class_methods('Controller')))</B><BR>
\n";



if ( ! class_exists($class)
    OR $method == 'controller'
    OR strncmp($method, '_', 1) == 0
    OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
    )
{
    show_404("{$class}/{$method}");
}


Here is my output :-

Code:
if ( ! class_exists(home)
OR index == 'controller'
OR strncmp(index, '_', 1) == 0
OR in_array(strtolower(index), array_map('strtolower', get_class_methods('Controller')))

if ( ! class_exists(home)
OR index == 'controller'
OR strncmp(index, '_', 1) == 0
OR in_array(strtolower(index), array_map('strtolower', get_class_methods('Controller')))


It seems as if STRNCMP is the cause - as my 'method' doesn't contain an underline character - It displays the 404 screen.


is my logic correct ?

How do I find / Fix my method ?

Ps, my root / main controller is /controllers/home.php (is correct)
#2

[eluser]sarah fox[/eluser]
its not my Method

It seems to e an error with my in_array command.

Code :-

Code:
$a= strncmp(".$method.", '_', 1);
echo "STRCOMPARE1 - $a<BR>\n";
$a=class_exists($class);
echo "STRCOMPARE2 - $a<BR>\n";
$a=(in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))));
echo "STRCOMPARE3 - $a<BR>\n";

Output :-

Code:
STRCOMPARE1 - -1
STRCOMPARE2 - 1
STRCOMPARE3 -


So, as in_array isn't producing any results - it activates the 404 page ?


is this right / Correct ?

Can someone advise how to fix it, & what that line actually means (in emglish)...


Ps, using my friends login, incorrectly....
#3

[eluser]WanWizard[/eluser]
in_array returns a boolean, which doesn't display with echo.

try
Code:
echo "STRCOMPARE3 - ",($a ? "TRUE" : "FALSE"),"<BR>\n";
#4

[eluser]sarah fox[/eluser]
Code:
$a= strncmp(".$method.", '_', 1);
echo "STRCOMPARE1 - $a<BR>\n";
$a=class_exists($class);
echo "STRCOMPARE2 - $a<BR>\n";
$a=(in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))));
echo "STRCOMPARE3 - $a<BR>\n";

echo "STRCOMPARE32 - ",($a ? "TRUE" : "FALSE"),"<BR>\n";


STRCOMPARE32 = FALSE

EDIT :- so, something in the 'in_array' command - Produces 'false' - which results in the 404 error.

Are there any steps I can take - How do I check what should be / Is in this array... - it seems to combine 3 functions (None of which I am familiar with)...
#5

[eluser]WanWizard[/eluser]
Show us that home controller. It's very unlikely that this is a CI issue...
#6

[eluser]sarah fox[/eluser]
Ive removed comment lines starting with //

Quote:&lt;?php

class Home extends Controller {

function Home()
{
parent::Controller();
echo "VIEWING ROOT FILE<BR>\n";

}

function about()
{

$data['head_text'] = trim("Title of page");

$this->smarty_parser->parse('about.tpl',$data);
}

function safety()
{

$data['head_text'] = trim("Title of page");

$this->smarty_parser->parse('safety.tpl',$data);
}


function examples()
{

/// LOGS DEBUG
//$this->output->enable_profiler(TRUE);
$data['head_text'] = trim("Title of page");

$this->smarty_parser->parse('examples.tpl',$data);
}



function goto()
{
if ($where = $this->input->post('newpage'))
redirect($where);
else
echo "GO WHERE $where<BR>\n";
}


function index()
{

/// LOGS DEBUG
$this->output->enable_profiler(TRUE);
// error_reporting(E_ALL);
// $data["rotate_head_message"]=header_message();
$data['show_map'] = "no";
$data['head_text'] = trim("Title of page");
#print_r($data);
# $pieces_title = explode(" ", $data['head_title');

// Title random number
$r=rand(1,100);
$data['title_random'] = $r;

$this->load->model('Header_rotate');
// If using multiple templates to display a page
// then each except the last one should be "displayed"
// to send it to the screen.
$this->smarty_parser->parse("mainpage.tpl", $data);
}


}
/* End of file root.php */
/* Location: ./system/application/controllers/welcome.php */


(Ive renamed the page from welcome/root/home etc - But all file-names are correct.. )

EDIT:- /controllers/home.php (correct / new filename)
#7

[eluser]WanWizard[/eluser]
Do you have error reporting enabled, and display errors set to 'on' in php.ini?

If so, you would have seen errors in your log files.

The issue here is that the class doesn't load, because 'goto' is a reserved word, that causes a parse error.
#8

[eluser]techgnome[/eluser]
I'm still fairly new to CI, but not programming... where is your $this->smarty_parser loaded? And I'm not sure what you mean about there being nothing about methods... the underscore is for "private" methods... meaning that they can't be accessed via the URL. Example: currently, with the controller above, the following url will work: index.php/home/about .... but if you were to change it to function _about .... then index.php/home/_about would not work. How ever, from within the controller $this->_about would work.

Good call on that Wan - I didn't even see that.

-tg
#9

[eluser]sarah fox[/eluser]
[quote author="WanWizard" date="1286478163"]Do you have error reporting enabled, and display errors set to 'on' in php.ini?

If so, you would have seen errors in your log files.
[/quote]

what errors in logs ?

php.ini

error_reporting = E_ALL & E_NOTICE
display_errors = On
error_log = 'c:\phpnew\logs\error.log'

(I also had error_log = /phpnew/logs/error.log )

- No logs & no php errors - Directory does exist...

PS - its the "Codeigniter" 404 file being displayed - Not a incorrect web-page (browser 404 page)... - so PHP is being run - & if I put phpinfo(); I do get results...

Quote:The issue here is that the class doesn't load, because 'goto' is a reserved word, that causes a parse error.

I'll remember that - for future, but thats still not the issue...

I saved my home.php script into a new name, & adjusted the controllers/home.php script as so :- (taking out a lot)..

Took out a LOT of functions - Bare basics...

Quote:&lt;?php

class Home extends Controller {

function Home()
{
parent::Controller();
echo "VIEWING ROOT FILE<BR>\n";

}


function index()
{

/// LOGS DEBUG
$this->output->enable_profiler(TRUE);
$data['show_map'] = "no";
$data['head_text'] = trim("Title of page");

$r=rand(1,100);
$data['title_random'] = $r;

$this->load->model('Header_rotate');
$this->smarty_parser->parse("mainpage.tpl", $data);
}


}
/* End of file root.php */
/* Location: ./system/application/controllers/welcome.php */

Still no go...

I'll check the $this->smarty_parser thing - However - Even if the templates don't get parsed as "smarty" - They'll be loaded / parsed as "something" (even if incorrect HTML code is shown...)
#10

[eluser]WanWizard[/eluser]
I've copied your home controller into a fresh CI 1.7.2 install here, and get the parse error.
You get the CI 404 error because 'get_class_methods('Controller')' doesn't return data, since the class didn't load.

If I change 'goto' to 'x', the home controller loads without problems.

If I copy the stripped home controller code in as per your post, it loads without problems (I get the "VIEWING ROOT FILE" text, and the can't find the model error).

Just checking, this controller is in /system/application/controllers/home.php ?




Theme © iAndrew 2016 - Forum software by © MyBB