1.Routing does not work. It calls every time my action_index, but i have a function named action_show, but from the routes 'about' => 'news/show' it isnt called, but instead index. and when i rename my root: '_root_' => 'news/show' it calls nothing. .htacces modified, localhost modified, tried on webserver and local: nothing works. Someone has an idea what goes wrong?
Oke, different Questions: Why are namespaces not working? Im trying to use them, but i get the Error-Message, that 'model/MODEL was not found', use statements the same. So as an example: in my controller i say 'use /Model/news'; ', but i get an Error 'could not find class news in 'model/Model'. Where are the 2 model´s coming from?
And: Do you have a better way to name the classes instead of theyre full name (like Controller_News_Index)? Im trying to separate the view-action from the controller-workload and give controller-specified functions to each subclass to prevent redeclaring each time the same function.
I appreciate the help, and please, tell me if i do smth the wrong way or have a bad type of programming that does not work well with FuelPHP (or HMVC, or overall just bad habits). Mistakes are there for learning from them.
Q1: Please var_dump $_SERVER at the top of your index.php and post the values of REQUEST_URI, QUERY_STRING, SCRIPT_NAME and PATH_INFO (if exists) here.
Q2: Namespaces work with backslashes, not forward slashes. So "use \Model\News".
As to the class names, the rules are simple:
1 - all filenames need to be lower case
2 - there is a one-to-one mapping between classname and filename
3 - you can use underscores or namespaces, or mix the two
4 - once you pick a name, don't use alternatives
So, a class like "Controller_Some_Class_Name" in the global namespace is stored in app/classes/controller/some/class/name.php, But so is the class "Name" in the namespace "\Controller\Some\Class", or the class "Class_Name" in the namespace "\Controller\Some.
Note that if you want to use the "Controller" namespace instead of the "Controller_" prefix, you need to enable this in the config.
Q2: I used Backslashes, i just wrote in "/" because it was too early to think it throught ^^ Sorry for that.
Q3: I already understand the namespace-basics, the problem is that even with the correct namespaces and naming of my classes, if i try to use them and request my Models it would instead put in "use \Model\news\news;" to => "use \Model\MODEL;\ . namespace would be "namespace \Model;". Still same error. Or it could not find the file specified. Or if it would find the file, it would not load the class even with correct written namespace.
And for the naming of classes: as you can see, i used Controller_News_Index::index() to give in the informations i need. The question was: can i rename it inside my script without writing __construct() {} and puttting a $this->class = new Controller_News_Index(); ? Otherwise its a pain in the back *hust* and not very clean.
Well, thank you so far for your answer. I appreciate the help.
And PS: If i use the original .htaccess, it complete gives up and prints out a 500 Server error (
Internal Server Error etc. pp.).
Only with the smaller one does it not break up.
Then there was the problem with the timezone, but i managed it to fix it by manually adressing it in my config.php. So, well... Hope that helps.
Funy fact: the original, on the other hand, works with localhost...
PHP Version 5.6 to 7.0 geupdated, then to 7.1 ... nothing works. It shows me an
404 - Page not found!
when i type in /news/show/fwaf . But when i use /news/show , its just like displaying the startpage ('_root_').
I dont know, maybe the redirect is getting overwritten by smth? And i cant use the original version of the .htaccess because... yeah, i have already written that.
Timezone must always be set, if it is not set in the php.ini. it is a PHP requirement for date functions, which is why Fuel checks for it, and gives an error if it is not set.
Your $_SERVER info looks fine, so that is not the problem.
What platform are you on? Windows? Linux? Something else? Which webserver (I assume Apache since you mention htaccess)? And what PHP setup? FPM? CGI? SAPI?
The htaccess supplied is tested on Apache in all combinations with PHP 5.x and 7.0. It has not been tested with 7.1, which may cause your issue, it might be the module tests fail.
I don't get what you want with Controller_News_Index. I see it being used as a parameter to View::forge(), which suggests it is not a controller at all, but a normal class used as a data provider. But you should be able to use it like that, the autoloader won't have any issue finding it, I just tested that here.
Because you mis-use a controller as an internal data provider, you mess up the controller detection system.
If you request "/news/show", this could mean:
- Controller_News_Show::action_index()
- Controller_News::action_show()
- Controller_News::router()
In this sequence. And because in your case, Controller_News_Show exists, it will load and call that, instead of Controller_News::action_show(), what you want it to load.
So you have made a design error. Your data provider classes should be models in the strict MVC sense. Or create them in app/classes/provider, and call them Provider_News_Show or something.
Make sure that the system folders (controller/model/presenter) in classes only contain the classes that belong there.
Now it uses my actions according to the following routes:
<?php
return array(
'_root_' => 'news/hello', // The default route
'_404_' => 'welcome/404', // The main 404 route
'_500_' => 'welcome/404', // The main 404 route
'news/show' => 'news/showNews', // Show News
);
When i delete my content from showNews now, it gives out that there are undefined variables... So that works... But _show after action_ does not work, and when i write _index, and i use _show in another action and try to call that, it uses the action_index and not action_show.... Well... thats unexpected... Do you have an answer to that?
Nah, jokes aside, well, most likely _show is messing it all up, and index is just flipping side with it. Most likely in the background it messes up everything you guys programmed. Damn, im good.
Well, that likely was the cause of everything. That explains why everything else in that action didnt work either.
So, im renaming all my actions with care, love and salt.... Much salt.