Codeigniter routing not working in some cases? - php

I got used to use Grocery CRUD library which eases CRUD process. When I'm going to use the edit process, The URI is would be some thing like http://www.example.com/users/get_users/edit/userID(num).
The issue is, If one of the users removes the userID this will gives an error due to the required parameter by edit method, So that I have tried to use Codeigniter routing as below
$route['users/get_users/edit'] = "users/get_users";
But this didn't work..!
Any idea please...

$route['users/get_users/edit/:num'] = "users/get_users";
It should be like this. And I think you getting error message because "users/get_users" still expects userID. Its better to come up with the error message as well.

Related

Laravel 7.6 - Route [login] not defined

I'm trying to build a simple rest api using the latest version of Laravel for a quite simple e-learning platform that I'm building using Reactjs. So far, everything seemed to be going well but then this error appeared. The strange thing is that, this error occurs only in two routes instead all the others work perfectly. This is a capure of my api.php file:
The routes that do not work are "posts" and "courses", as I have already said, the others work well, the only thing is that, as regards "teachers", "lessons" and "specialties", I cannot understand why, for example, if I make a petition with the POST method to "/ specialties / id", the requested data is not found.
Could any of you help me to solve these problems?
This, instead, is a capture of my "specialties" table file:
and finally, these are the capture of my "SpecialtyController" file:
Thanks in advance
Regards

How to implement pagination along with sorting results in Laravel

I'm pretty new to Laravel, and still exploring it's features and possibilities, and I've came across a strange issue that I don't quite understand.
First of all, I'm using Laravel 5.0 and I'm trying to make pagination of results that came from model alongside with sorting them.
Here is the code that works, but without sorting:
News::paginate(5);
And here is what I need, but doesn't work:
News::paginate(5)->orderByDesc('published_at');
I've tried doing it like so:
News::all()->sortByDesc('published_at')->paginate(5);
But then, when I call render() method inside view it throws error. I would like to use model's approach since it's handy and few more things depend on it, and not query builder method. Also, would like, if possible to avoid manual or any kind of custom pagination. Thanks
You should write this. This will solve your problem
News::orderBy('published_at','desc')->paginate(5);

Handling sharp in the url

I am trying to pass a name variable via this routing pattern.
<controller:product>/<name:[^\/]+> => 'product/view'
My aim is to get the $name in my actionView of the product controller, it works most of the times, but what I've discovered is it fails to pass the name if it contains a sharp (#) , for example sending a request
/product/test%20#something
Will fail, as far as I understood it is trying to find actionTest instead.
It might be a solution to set the default action of the controller to go to the view, but I want a better solution for this. I am sure there is a yii way to solve this.
Also another solution is to urlencode($productName), but it makes the URL look more ugly.

check for error

I have my own AppCotroller and using the beforeRender method to make changes to $this->viewPath based on the desired output format.
Is there a way I can check if Cake is currently outputting an error message? If I change the viewPath and then it's displaying an error (like can't load model, etc) it will error on the error :)
By the time Cake is displaying the error it should already be too late to do something about it. Not quite sure why you'd get an error about missing models when you change the viewPath, I hope that was just an example.
You might have some luck overriding or extending the ErrorHandler to intercept errors, but I wouldn't recommend doing that. Errors don't exist to be hidden, they're there to tell you something.
Creating a custom View might be a good idea depending on what you want to do (see the MediaView as an example of an alternative view).
The best thing to do though should be to avoid triggering errors by only allowing certain, predefined views to be set or making sure that a certain view file exists before trying to invoke it.

How do I resolve an "Invalid Node" error in the ACL tutorial in CakePHP?

I created an application using the method described in the CakePHP Documentation but after I try to log in there is an error which says,
DbAcl::allow() - Invalid node [CORE\cake\libs\controller\components\acl.php, line 325]
I did exactly same as mentioned in the website but after loggin in I
am given this error message. Please help me rectify this.
Not enough information to provide an answer, but that error means that something is wrong in your ACL trees, ARO or ACO, or you're sending the wrong parameter to allow().
Try using the acl console to find out whether your ARO/ACO trees are organized properly, as described in the tutorial. If they are not, truncate your ACL tables and start inserting from scratch. But very carefully this time! :-P
yes. something is definitely wrong because as described in the method there the aros tables should have the structure exactly to that of mentioned in that section. when I created groups using the CRUD generated by cakephp all went properly to the database but the users info is not updated in the aros table. I will again give it a try to see if I am doing something wrong..
Super old question, but, I came across this problem and couldn't find an answer to my problem (even in this thread).
My problem actually was that I had a method with the same name that the controller, let me explain what I mean with some code:
class Users extends AppController{
public function users(){
}
}
Changing the method name fixed the problem for me.
PS: using cakePHP 1.2

Categories