I am looking at writing a application that requires search engine friendly URLs for a lot of pages. So for example to access say site.com/blah could be a user or a page. For this I was thinking of having a table where I have the URL and then I have a column with the controller, action and any parameters such as id of a page or a user.
I know a db look-up can be slow so I am wondering if this is the best way of going about things?
If you have to use the same route URL (site.com/blah) for two different controller/action, the only way is to use database lookup. When a new user signs up, store the username and the user ID in the database and the route type to 'User' for this username. When a new page is created, store the page name and the page ID in the database and the route type to 'Page'.
When a URL is requested, check the name against the database and get the route type and forward accordingly.
Related
I know you can save sessions actions of user in a file (logs) or database. But this file (or line in database) is rewrited in every action that user make, for example:
If user start in login and then go to home, later go to about; this file is rewrite to from: home > to about.
I know it is not the complete quote generated in log/db. Is it possible to storage the first action (from login to home) and the second (from home to about)? How can I do it?
Thanks
I've been using Laravel Audits and it's pretty cool, give it a try.
It tracks pretty much everything you need, and shows you what was created and the old and new values when something is edited. but downfall is it does not track changes pivot tables
Check it out here: Laravel Audits
Maybe have a look at https://github.com/spatie/laravel-activitylog which allows you to specify your own logging requirements.
Laravel requests allow to get a lot of informations.
You can create a table in your database and a middleware which get the request anytime a route is called and store informations like the route called, the user id or even his referer in the table.
Check it out for more info about requests
We are developing an application in Laravel 5 where users can login and based on the licenses assigned to the user, multiple "content types" are available within the app. The business logic and presentation logic differs based on the selected content type. The user can select the content type to work with, or, if only one license is available, will be directed to the homepage of that content type.
Now I am trying to figure out how to handle the selected content type. Storing this in a session is imo not the way to go because a user must be able to use multiple content types in one browser session simultaneously.
I figured I need to start with grouping all relevant routes and prefixes them with {contentType}. Also, add a Middleware (named something like SelectContentTypeMiddleware) and let that middleware check if the content type exists, and if the logged in user is allowed to have access to it.
Furthermore, every descending route (in the {contentType} prefix route group) also must handle the route parameter $contentType.
I am trying to figure out of this is the right approach. I was looking at this blogpost which addresses the case for setting the app locale. Using app()->setLocale($locale) the locale for that request is set. I was wondering if a similar approach for my case makes sense, or that including the route parameter $contentType in every route is more advisable.
I am developing a dynamic website using PHP. When a user of the website creates an account, a profile page should be created for that user. Say, a user called 'dev23' creates an account on my website, his profile should be accessible through the link www.mysite.com/dev23
How do I create such a thing? Should I create a standard page like userprofile.php which is populated with data specific to the username provided? Or should I create a permanent webpage for every user?
Please let me know the right approach to this porblem.
Is the www.mysite.com/dev23 meant to be public or only visible to the logged in user?
If it is only visible to the logged in user, you can create a myprofile.php file which retrieves the logged in user from the session and retrieves data accordingly.
If it is meant to be a URL that other users can hit, you probably want some sort of userprofile.php page with data passed along to identify the user to be viewed. For example, the url might be www.mysite.com/userprofile.php?user=dev23. If you are using Apache for your web server, you can look at using mod_rewrite to make the URL prettier. Thus, you could have the URL www.mysite.com/user/dev23 routed to userprofile.php?user=dev23 and your PHP processes the same. It is just a means of making URLs be more user friendly than a naked query string. This is common amongst many PHP-based CMS systems such as WordPress, Joomla, etc.
Ideally you should be creating a single file that handles all users.
Certain frameworks like SkyPHP allow this by defining the attributes after a valid page as "queryfolders" which can be used much like GET/POST variables.
If you are not using a framework, I might suggest you look into using one to simplify your tasks.
SkyPHP also has a functionality where a single field in a table can be used to pull this data simply by defining the page as _table.field_name_
It will check to see if there is a matching table and field to pull the data from and will automatically pull the id of the record whose field's value matches that of the url and assign it to a variable.
Example... If we have a table called category and a field named slug, one would create a page named _category.slug_.php
Then the url... http://mydomain.com/watches would look for "watches" in category.slug and pull back the identifier of the record as $category_id with $category_slug available also.
It would solve your issue if you are willing to give it a shot.
Again refer to the documentation here... http://switchbreak.com/skyphp
I'm newbie to Joomla module development, and would like to implement a custom module for Joomla CMS.
I need to display the sales history of the logged in user. For example, a user with [username] = "US001" logged in successfully, and go to view what sales orders have done by him. And the module display the data recordset in table format by passing the "US001" as username parameter to my database and retrieve the data.
How do I detect the user logged in and then remember the [username] for the whole session?
How can I pass this [username] parameter, e.g. "US001" to my external URL for retrieving data record set? My database for every user's sales history is in another different IP's server.
After query the data, how to return back my dataset to the module and draw my table out on that module?
Additional function would be Admin's user able to control which field to be display, eg. 'age', 'e-mail', etc on the table in module.
You want to access the user object. Joomla already has most of what you need built in, you just pull up the current user and you have the info.
To start with, you will need to get the current user info -
`$user =& JFactory::getUser();`
if ($user->guest) will tell you if the user is logged in, $user->name will give you the username
You will have to pass any info from Joomla to the external URL using either GET or POST. Easiest way is to pass it as part of the URL query string (GET) external.url.com/database-page.html?username=name; ?> or similar
Again, GET or POST the values you want to use back to the page containing your module.
Not sure what you mean here, but it sounds like you need to add parameters (called form fields in 1.6 and newer) to your module so you can turn on or off the display of some of the data the module will be getting.
User object tutorial - http://docs.joomla.org/Accessing_the_current_user_object
Parameters - http://docs.joomla.org/Standard_parameter_types
Form fields - http://docs.joomla.org/Form_field
Lastly, it sounds like you would be better served creating a component instead of a module, unless you plan to display the database info you are pulling as part of another page that will be displaying the main content.
Busy building my first web application in CodeIgniter and wanted to work out the best way of gathering ID in my Admin function for Edit, Delete statements.
I realised I can use any of the following:
Pass the ID through the controller.
Collect the ID from the URI segment.
Collect the ID from a hidden form field.
Which is the best based on security concerns. i.e. People fiddling with the URL, etc.
I prefer to use the URL for unique IDs, that way you get nice-looking URLs that people can bookmark. You shouldn't rely on how you pass the data for security, you should be doing input validation within your controller regardless of how you pass it.
If this is for an admin section, it should may no difference. Unless a user is authorized to view the output of say, the Admin Controller, they should see "page does not exist" for each one of those methods.
Collect the ID from the URI segment. is my choise..nice url!